time.sleep(0.5)
logger = logging.getLogger('wsgiserver') class MetricsMiddleware: """Collect request metrics""" def __init__(self, app): self.app = app self.request_count = 0 self.error_count = 0 def __call__(self, environ, start_response): self.request_count += 1 def custom_start_response(status, headers, exc_info=None): if status.startswith('5'): self.error_count += 1 return start_response(status, headers, exc_info) return self.app(environ, custom_start_response) wsgiserver 0.2
start_time = time.time() with ThreadPoolExecutor(max_workers=50) as executor: results = list(executor.map(lambda _: make_request(), range(num_requests))) exc_info) return self.app(environ
COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt wsgiserver 0.2
duration = time.time() - start_time successful = sum(results)
