Changeset 1152
- Timestamp:
- 06/20/06 18:28:59
- Files:
-
- trunk/cherrypy/test/benchmark.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/benchmark.py
r1141 r1152 2 2 3 3 Usage: 4 benchmark.py --null --notests --help -- modpython --ab=path --apache=path4 benchmark.py --null --notests --help --cpmodpy --modpython --ab=path --apache=path 5 5 6 6 --null: use a null Request object (to bench the HTTP server only) … … 8 8 you to check the tested pages with a browser 9 9 --help: show this help message 10 -- modpython: start up apache on 8080 (with a custom modpython11 config) and run the tests10 --cpmodpy: run tests via apache on 8080 (with the builtin _cpmodpy) 11 --modpython: run tests via apache on 8080 (with modpython_gateway) 12 12 --ab=path: Use the ab script/executable at 'path' (see below) 13 13 --apache=path: Use the apache script/exe at 'path' (see below) … … 268 268 269 269 270 started = False271 def startup(req=None):272 """Start the CherryPy app engine with no server (for WSGI)."""273 global started274 if not started:275 started = True276 cherrypy.engine.start(blocking=False)277 return 0 # apache.OK278 279 280 281 270 # modpython and other WSGI # 282 271 283 272 def startup_modpython(req=None): 284 """Start the CherryPy app server in 'serverless' mode (for WSGI).""" 285 global started 286 if not started: 287 started = True 273 """Start the CherryPy app server in 'serverless' mode (for modpython/WSGI).""" 274 if cherrypy.engine.state == cherrypy._cpengine.STOPPED: 288 275 if req.get_options().has_key("nullreq"): 289 cherrypy. server.request_class = NullRequest290 cherrypy. server.response_class = NullResponse276 cherrypy.engine.request_class = NullRequest 277 cherrypy.engine.response_class = NullResponse 291 278 ab_opt = req.get_options().get("ab", "") 292 279 if ab_opt: … … 294 281 AB_PATH = ab_opt 295 282 cherrypy.engine.start(blocking=False) 296 297 import modpython_gateway298 return modpython_gateway.handler(req)283 if cherrypy.engine.state == cherrypy._cpengine.STARTING: 284 cherrypy.engine.wait() 285 return 0 # apache.OK 299 286 300 287 mp_conf_template = """ … … 307 294 <Location /> 308 295 SetHandler python-program 309 PythonHandler cherrypy.test.benchmark::startup_modpython 310 PythonOption application cherrypy._cpwsgi::wsgiApp 296 PythonFixupHandler cherrypy.test.benchmark::startup_modpython 297 PythonHandler modpython_gateway::handler 298 PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp 311 299 PythonDebug On 312 300 %s%s … … 314 302 """ 315 303 316 def run_modpython(): 304 cpmodpy_template = """ 305 # Apache2 server configuration file for benchmarking CherryPy with mod_python. 306 307 DocumentRoot "/" 308 Listen 8080 309 LoadModule python_module modules/mod_python.so 310 311 <Location /> 312 SetHandler python-program 313 PythonHandler cherrypy._cpmodpy::handler 314 PythonOption cherrypy.setup cherrypy.test.benchmark::startup_modpython 315 PythonDebug On 316 %s%s 317 </Location> 318 """ 319 320 def run_modpython(use_wsgi=False): 317 321 # Pass the null and ab=path options through Apache 318 322 nullreq_opt = "" … … 324 328 ab_opt = " PythonOption ab %s\n" % opts["--ab"] 325 329 326 conf_data = mp_conf_template % (ab_opt, nullreq_opt) 330 if use_wsgi: 331 conf_data = mp_conf_template % (ab_opt, nullreq_opt) 332 else: 333 conf_data = cpmodpy_template % (ab_opt, nullreq_opt) 327 334 mpconf = os.path.join(curdir, "bench_mp.conf") 328 335 … … 343 350 344 351 if __name__ == '__main__': 345 longopts = ['modpython', 'null', 'notests', 'help', 'ab=', 'apache='] 352 longopts = ['cpmodpy', 'modpython', 'null', 'notests', 353 'help', 'ab=', 'apache='] 346 354 try: 347 355 switches, args = getopt.getopt(sys.argv[1:], "", longopts) … … 378 386 start = time.time() 379 387 380 if "-- modpython" in opts:388 if "--cpmodpy" in opts: 381 389 run_modpython() 390 elif "--modpython" in opts: 391 run_modpython(use_wsgi=True) 382 392 else: 383 393 if "--null" in opts:

