Worker that makes sequential requests on a persistent connection.
(num_requests: int)
| 318 | remainder = total_requests % concurrency |
| 319 | |
| 320 | def worker_task(num_requests: int) -> None: |
| 321 | """Worker that makes sequential requests on a persistent connection.""" |
| 322 | worker_latencies = [] |
| 323 | worker_errors = [] |
| 324 | |
| 325 | try: |
| 326 | client = DirtyClient(self.socket_path, timeout=timeout) |
| 327 | client.connect() |
| 328 | |
| 329 | for _ in range(num_requests): |
| 330 | try: |
| 331 | start = time.perf_counter() |
| 332 | client.execute(BENCHMARK_APP, action, *args, **kwargs) |
| 333 | elapsed = (time.perf_counter() - start) * 1000 |
| 334 | worker_latencies.append(elapsed) |
| 335 | except Exception as e: |
| 336 | worker_errors.append(str(e)) |
| 337 | # Reconnect on error |
| 338 | try: |
| 339 | client.close() |
| 340 | client = DirtyClient(self.socket_path, timeout=timeout) |
| 341 | client.connect() |
| 342 | except Exception: |
| 343 | pass |
| 344 | |
| 345 | client.close() |
| 346 | except Exception as e: |
| 347 | worker_errors.append(f"Connection error: {e}") |
| 348 | |
| 349 | # Add results to shared lists |
| 350 | with lock: |
| 351 | latencies.extend(worker_latencies) |
| 352 | errors.extend(worker_errors) |
| 353 | |
| 354 | # Run concurrent workers |
| 355 | with ThreadPoolExecutor(max_workers=concurrency) as executor: |
nothing calls this directly
no test coverage detected