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

Class IsolatedBenchmark

benchmarks/dirty_benchmark.py:192–367  ·  view source on GitHub ↗

Run benchmarks directly against the dirty pool without HTTP. Spawns a standalone dirty arbiter and workers, then runs concurrent clients to measure performance.

Source from the content-addressed store, hash-verified

190
191
192class IsolatedBenchmark:
193 """
194 Run benchmarks directly against the dirty pool without HTTP.
195
196 Spawns a standalone dirty arbiter and workers, then runs concurrent
197 clients to measure performance.
198 """
199
200 def __init__(
201 self,
202 dirty_workers: int = 2,
203 dirty_threads: int = 1,
204 dirty_timeout: int = 300,
205 verbose: bool = False,
206 ):
207 self.dirty_workers = dirty_workers
208 self.dirty_threads = dirty_threads
209 self.dirty_timeout = dirty_timeout
210 self.verbose = verbose
211
212 self.arbiter = None
213 self.arbiter_pid = None
214 self.socket_path = None
215 self._tmpdir = None
216
217 def start(self):
218 """Start the dirty arbiter and workers."""
219 # Create temp directory for socket
220 self._tmpdir = tempfile.mkdtemp(prefix="dirty-bench-")
221 self.socket_path = os.path.join(self._tmpdir, "arbiter.sock")
222
223 # Create config and logger
224 cfg = MockConfig(
225 dirty_apps=[BENCHMARK_APP],
226 dirty_workers=self.dirty_workers,
227 dirty_threads=self.dirty_threads,
228 dirty_timeout=self.dirty_timeout,
229 )
230 log = MockLogger(verbose=self.verbose)
231
232 # Fork arbiter process
233 pid = os.fork()
234 if pid == 0:
235 # Child process - run arbiter
236 try:
237 arbiter = DirtyArbiter(cfg, log, socket_path=self.socket_path)
238 arbiter.run()
239 except Exception as e:
240 print(f"Arbiter error: {e}")
241 finally:
242 os._exit(0)
243
244 # Parent process
245 self.arbiter_pid = pid
246
247 # Wait for arbiter socket to be ready
248 for _ in range(50): # 5 seconds max
249 if os.path.exists(self.socket_path):

Callers 5

run_isolated_suiteFunction · 0.85
run_payload_suiteFunction · 0.85
run_quick_testFunction · 0.85
run_config_sweepFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected