MCPcopy
hub / github.com/benoitc/gunicorn / run_config_sweep

Function run_config_sweep

benchmarks/dirty_benchmark.py:773–850  ·  view source on GitHub ↗

Sweep through different configurations to find optimal settings. Tests combinations of workers and threads.

(verbose: bool = False)

Source from the content-addressed store, hash-verified

771
772
773def run_config_sweep(verbose: bool = False) -> list[BenchmarkResult]:
774 """
775 Sweep through different configurations to find optimal settings.
776
777 Tests combinations of workers and threads.
778 """
779 results = []
780
781 configs = [
782 (1, 1), # Baseline
783 (2, 1), # 2 workers, 1 thread each
784 (4, 1), # 4 workers, 1 thread each
785 (2, 2), # 2 workers, 2 threads each
786 (2, 4), # 2 workers, 4 threads each
787 (4, 2), # 4 workers, 2 threads each
788 ]
789
790 print("\nRunning configuration sweep...")
791
792 for workers, threads in configs:
793 print(f"\n Testing workers={workers}, threads={threads}...")
794
795 bench = IsolatedBenchmark(
796 dirty_workers=workers,
797 dirty_threads=threads,
798 verbose=verbose,
799 )
800
801 try:
802 bench.start()
803 bench.warmup()
804
805 # Run a standard workload
806 start_time = time.perf_counter()
807 latencies, errors = bench.run_benchmark(
808 action="mixed_task",
809 args=(20, 20), # 20ms sleep + 20ms CPU
810 total_requests=1000,
811 concurrency=50,
812 )
813 duration = time.perf_counter() - start_time
814
815 result = BenchmarkResult(
816 scenario=f"config_w{workers}_t{threads}",
817 config={
818 "dirty_workers": workers,
819 "dirty_threads": threads,
820 "task": "mixed_task(20, 20)",
821 "concurrency": 50,
822 },
823 total_requests=1000,
824 successful=len(latencies),
825 failed=len(errors),
826 errors=errors[:5] if errors else [],
827 duration_sec=round(duration, 2),
828 requests_per_sec=round(len(latencies) / duration, 1),
829 latency_ms=LatencyStats.from_samples(latencies),
830 )

Callers 1

mainFunction · 0.85

Calls 7

startMethod · 0.95
warmupMethod · 0.95
run_benchmarkMethod · 0.95
stopMethod · 0.95
IsolatedBenchmarkClass · 0.85
from_samplesMethod · 0.80
BenchmarkResultClass · 0.70

Tested by

no test coverage detected