Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1152

Show
Ignore:
Timestamp:
06/20/06 18:28:59
Author:
fumanchu
Message:

Updated benchmark to work with new _cpmodpy module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/benchmark.py

    r1141 r1152  
    22 
    33    Usage: 
    4         benchmark.py --null --notests --help --modpython --ab=path --apache=path 
     4        benchmark.py --null --notests --help --cpmodpy --modpython --ab=path --apache=path 
    55     
    66    --null:        use a null Request object (to bench the HTTP server only) 
     
    88                   you to check the tested pages with a browser 
    99    --help:        show this help message 
    10     --modpython:   start up apache on 8080 (with a custom modpython 
    11                    config) and run the tests 
     10    --cpmodpy:     run tests via apache on 8080 (with the builtin _cpmodpy) 
     11    --modpython:   run tests via apache on 8080 (with modpython_gateway) 
    1212    --ab=path:     Use the ab script/executable at 'path' (see below) 
    1313    --apache=path: Use the apache script/exe at 'path' (see below) 
     
    268268 
    269269 
    270 started = False 
    271 def startup(req=None): 
    272     """Start the CherryPy app engine with no server (for WSGI).""" 
    273     global started 
    274     if not started: 
    275         started = True 
    276         cherrypy.engine.start(blocking=False) 
    277     return 0 # apache.OK 
    278  
    279  
    280  
    281270#                         modpython and other WSGI                         # 
    282271 
    283272def 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: 
    288275        if req.get_options().has_key("nullreq"): 
    289             cherrypy.server.request_class = NullRequest 
    290             cherrypy.server.response_class = NullResponse 
     276            cherrypy.engine.request_class = NullRequest 
     277            cherrypy.engine.response_class = NullResponse 
    291278        ab_opt = req.get_options().get("ab", "") 
    292279        if ab_opt: 
     
    294281            AB_PATH = ab_opt 
    295282        cherrypy.engine.start(blocking=False) 
    296      
    297     import modpython_gateway 
    298     return modpython_gateway.handler(req) 
     283    if cherrypy.engine.state == cherrypy._cpengine.STARTING: 
     284        cherrypy.engine.wait() 
     285    return 0 # apache.OK 
    299286 
    300287mp_conf_template = """ 
     
    307294<Location /> 
    308295    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 
    311299    PythonDebug On 
    312300%s%s 
     
    314302""" 
    315303 
    316 def run_modpython(): 
     304cpmodpy_template = """ 
     305# Apache2 server configuration file for benchmarking CherryPy with mod_python. 
     306 
     307DocumentRoot "/" 
     308Listen 8080 
     309LoadModule 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 
     320def run_modpython(use_wsgi=False): 
    317321    # Pass the null and ab=path options through Apache 
    318322    nullreq_opt = "" 
     
    324328        ab_opt = "    PythonOption ab %s\n" % opts["--ab"] 
    325329     
    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) 
    327334    mpconf = os.path.join(curdir, "bench_mp.conf") 
    328335     
     
    343350 
    344351if __name__ == '__main__': 
    345     longopts = ['modpython', 'null', 'notests', 'help', 'ab=', 'apache='] 
     352    longopts = ['cpmodpy', 'modpython', 'null', 'notests', 
     353                'help', 'ab=', 'apache='] 
    346354    try: 
    347355        switches, args = getopt.getopt(sys.argv[1:], "", longopts) 
     
    378386    start = time.time() 
    379387     
    380     if "--modpython" in opts: 
     388    if "--cpmodpy" in opts: 
    381389        run_modpython() 
     390    elif "--modpython" in opts: 
     391        run_modpython(use_wsgi=True) 
    382392    else: 
    383393        if "--null" in opts: 

Hosted by WebFaction

Log in as guest/cpguest to create tickets