33"""
44
55import logging
6+ import concurrent
67
78from concurrent .futures import ThreadPoolExecutor
8- from concurrent .futures import TimeoutError
99from multiprocessing import Process , Queue
1010from threading import Event
1111import time
@@ -72,7 +72,7 @@ def _timeout_fn(fn, timeout, ev_stop):
7272 future = executor .submit (fn )
7373 try :
7474 r = future .result (timeout )
75- except TimeoutError :
75+ except concurrent . futures . TimeoutError :
7676 # Timeout expires.
7777 # Now it's time to stop the thread and get the result.
7878 ev_stop .set ()
@@ -105,6 +105,7 @@ def _cnt_operations(svc_call, res_queue, timeout):
105105 timeout: time used to repeat the service call.
106106 """
107107 ev_stop = Event ()
108+ # pylint: disable=unnecessary-lambda-assignment
108109 operation = lambda : _repeat_svc_call (svc_call , ev_stop )
109110 cnt = _timeout_fn (operation , timeout , ev_stop )
110111 res_queue .put (cnt ) # Pass the total count to the parent process.
@@ -140,7 +141,7 @@ def _start_proc(_perf_wrapper_fn, svc_call, timeout):
140141 be terminated. The result got by the child process will be stored in the ``Queue``.
141142 """
142143 res_queue = Queue ()
143- p = Process (target = ( lambda : _perf_wrapper_fn (svc_call , res_queue , timeout ) ))
144+ p = Process (target = lambda : _perf_wrapper_fn (svc_call , res_queue , timeout ))
144145 p .start ()
145146 return p , res_queue
146147
@@ -155,7 +156,7 @@ def _start_proc_and_wait(_perf_wrapper_fn, svc_call):
155156 The result returned by the wrapper function. e.g. the timing result.
156157 """
157158 res_queue = Queue ()
158- p = Process (target = ( lambda : _perf_wrapper_fn (svc_call , res_queue ) ))
159+ p = Process (target = lambda : _perf_wrapper_fn (svc_call , res_queue ))
159160 p .start ()
160161 # NOTE: The order matters here. There could be some deadlock if "join" before
161162 # "get" according to the document of Python:
@@ -170,17 +171,17 @@ def _test_throughput(svc_call):
170171 Args:
171172 svc_call: function to invoke the service call.
172173 """
173- # 1. Start N processes to simulate N apps (see our design for details).
174+ # 1. Start N processes to simulate N apps (see our design for details).
174175 task_num = THROUGHPUT_TEST_TASK_NUM
175176 time_total = THROUGHPUT_TEST_TASK_TIME
176177 tasks = []
177178 for _ in range (task_num ):
178179 # 2. Each process invokes the CCNP API (either via SDK or service directly) repeatedly
179- # until the timeout T expires (see our design details).
180- p , res_queue = _start_proc (_cnt_operations , svc_call , time_total )
181- tasks .append (PerfTask (p , res_queue ))
180+ # until the timeout T expires (see our design details).
181+ p , res_queue = _start_proc (_cnt_operations , svc_call , time_total )
182+ tasks .append (PerfTask (p , res_queue ))
182183
183- # 3. Calculate the average ops (total count of completed API calls in N threads divided by T).
184+ # 3. Calculate the average ops (total count of completed API calls in N threads divided by T).
184185 cnt_total = 0
185186 for t in tasks :
186187 cnt = t .queue .get ()
@@ -189,6 +190,7 @@ def _test_throughput(svc_call):
189190 ops_avg = cnt_total / time_total
190191
191192 # Log out the result for latter analysis.
193+ # pylint: disable=logging-fstring-interpolation
192194 LOG .info (f"Perf test average throughput is: { ops_avg } ops (operations per second)" )
193195
194196def _test_response (svc_call ):
@@ -197,20 +199,22 @@ def _test_response(svc_call):
197199 Args:
198200 svc_call: function to invoke the service call.
199201 """
200- # 1. Repeat the steps below M times (M = 20 is the current setting):
202+ # 1. Repeat the steps below M times (M = 20 is the current setting):
201203 repeat_times = RESPONSE_TEST_REPEAT_TIME
202204 t_cost_total = 0
203205 for _ in range (repeat_times ):
204- # Start a new process to simulate an app. In the process:
205- # Begin timing.
206- # Call (one immediately after another) the CCNP API (either via SDK or request to service directly).
207- # End timing.
208- # Record the time consumption and exit.
206+ # Start a new process to simulate an app. In the process:
207+ # Begin timing.
208+ # Call (one immediately after another) the CCNP API (either via SDK or
209+ # request to service directly).
210+ # End timing.
211+ # Record the time consumption and exit.
209212 t_cost = _start_proc_and_wait (_timing_response , svc_call )
210213 t_cost_total += t_cost
211214
212215 # 2. Calculate the average response time (total time divided by M).
213216 t_cost_avg = t_cost_total / repeat_times
217+ # pylint: disable=logging-fstring-interpolation
214218 LOG .info (f"Perf test average response time is: { t_cost_avg / 1000000 } ms (milliseconds)" )
215219
216220def _sdk_get_cc_measurement ():
@@ -257,9 +261,9 @@ def test_ccnp_init():
257261 """
258262 # TODO:
259263 # Repeat R times (R = 20 is the current setting) and calculate the average time
260- # (total times divided by R):
261- # Begin timing.
262- # Start CCNP deployment (incl. CCNP Device Plugin and CCNP Service).
263- # Polling the readiness of CCNP service until it's ready.
264- # End timing.
265- # Calculate the initialization time using end time subtracted by begin time.
264+ # (total times divided by R):
265+ # Begin timing.
266+ # Start CCNP deployment (incl. CCNP Device Plugin and CCNP Service).
267+ # Polling the readiness of CCNP service until it's ready.
268+ # End timing.
269+ # Calculate the initialization time using end time subtracted by begin time.
0 commit comments