MCPcopy
hub / github.com/redis/redis-py / run

Method run

benchmarks/otel_benchmark.py:319–355  ·  view source on GitHub ↗

Run the load generator for the configured duration.

(self)

Source from the content-addressed store, hash-verified

317 pass # Ignore errors in resource sampling
318
319 def run(self) -> BenchmarkResult:
320 """Run the load generator for the configured duration."""
321 self.latencies = []
322 self.errors = 0
323 self.first_error = None
324 self.cpu_samples = []
325 self.memory_samples = []
326
327 # Initialize CPU percent tracking
328 if self._process:
329 try:
330 self._process.cpu_percent(interval=None)
331 except Exception:
332 pass
333
334 print(f" Running load for {self.config.duration_seconds}s...")
335 start_time = time.monotonic()
336 end_time = start_time + self.config.duration_seconds
337 last_sample_time = start_time
338 sample_interval = 0.5 # Sample resources every 500ms
339
340 while time.monotonic() < end_time:
341 latency = self._run_operation()
342 if latency > 0:
343 self.latencies.append(latency)
344
345 # Sample resources periodically
346 current_time = time.monotonic()
347 if current_time - last_sample_time >= sample_interval:
348 self._sample_resources()
349 last_sample_time = current_time
350
351 # Final resource sample
352 self._sample_resources()
353
354 actual_duration = time.monotonic() - start_time
355 return self._calculate_results(actual_duration)
356
357 def _calculate_results(self, duration: float) -> BenchmarkResult:
358 """Calculate benchmark results from collected latencies."""

Callers 4

run_baseline_scenarioFunction · 0.95
run_iterationFunction · 0.95
mainFunction · 0.45

Calls 5

_run_operationMethod · 0.95
_sample_resourcesMethod · 0.95
_calculate_resultsMethod · 0.95
monotonicMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected