summaryrefslogtreecommitdiff
path: root/cherrypy
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2006-03-02 08:05:04 +0000
committerRobert Brewer <fumanchu@aminus.org>2006-03-02 08:05:04 +0000
commit16d0f542f72e1966fe00d1ba73c523e4fa4417e6 (patch)
treed2ee96e5311bc0b5db1f14f4b6b181e151f2548a /cherrypy
parentb944a402043843e7f7e81da79ceba5ddcb158113 (diff)
downloadcherrypy-git-16d0f542f72e1966fe00d1ba73c523e4fa4417e6.tar.gz
New Engine.response_class attribute (which allows a new -null switch for benchmark.py, to show how much of the request is spent in the HTTP server as opposed to the Request object).
Diffstat (limited to 'cherrypy')
-rw-r--r--cherrypy/_cpengine.py3
-rw-r--r--cherrypy/test/bench_mp.conf9
-rw-r--r--cherrypy/test/benchmark.py45
3 files changed, 54 insertions, 3 deletions
diff --git a/cherrypy/_cpengine.py b/cherrypy/_cpengine.py
index f1180c4c..7ba42780 100644
--- a/cherrypy/_cpengine.py
+++ b/cherrypy/_cpengine.py
@@ -20,6 +20,7 @@ class Engine(object):
"""The application server engine, connecting HTTP servers to Requests."""
request_class = _cphttptools.Request
+ response_class = _cphttptools.Response
def __init__(self):
self.state = STOPPED
@@ -186,6 +187,6 @@ class Engine(object):
r = self.request_class(clientAddress[0], clientAddress[1],
remoteHost, scheme)
cherrypy.serving.request = r
- cherrypy.serving.response = _cphttptools.Response()
+ cherrypy.serving.response = self.response_class()
return r
diff --git a/cherrypy/test/bench_mp.conf b/cherrypy/test/bench_mp.conf
index bbf4cb11..748d679f 100644
--- a/cherrypy/test/bench_mp.conf
+++ b/cherrypy/test/bench_mp.conf
@@ -6,7 +6,14 @@ LoadModule python_module modules/mod_python.so
<Location />
SetHandler python-program
- PythonFixupHandler cherrypy.test.benchmark::startup
+
+ <IfDefine !nullreq>
+ PythonFixupHandler cherrypy.test.benchmark::startup
+ </IfDefine>
+ <IfDefine nullreq>
+ PythonFixupHandler cherrypy.test.benchmark::startup_null
+ </IfDefine>
+
PythonHandler modpython_gateway::handler
PythonOption application cherrypy._cpwsgi::wsgiApp
PythonDebug On
diff --git a/cherrypy/test/benchmark.py b/cherrypy/test/benchmark.py
index 4f9e7ffc..2e7d1671 100644
--- a/cherrypy/test/benchmark.py
+++ b/cherrypy/test/benchmark.py
@@ -9,6 +9,7 @@ import time
import traceback
import cherrypy
+from cherrypy.lib import httptools
MOUNT_POINT = "/cpbench/users/rdelon/apps/blog"
@@ -211,6 +212,30 @@ def run_standard_benchmarks():
print_chart(size_chart())
+class NullRequest:
+ """A null HTTP request class, returning 204 and an empty body."""
+
+ def __init__(self, remoteAddr, remotePort, remoteHost, scheme="http"):
+ pass
+
+ def close(self):
+ pass
+
+ def run(self, requestLine, headers, rfile):
+ cherrypy.response.status = "204 No Content"
+ cherrypy.response.header_list = [("Content-Type", 'text/html'),
+ ("Server", "Null CherryPy"),
+ ("Date", httptools.HTTPDate()),
+ ("Content-Length", "0"),
+ ]
+ cherrypy.response.body = [""]
+ return cherrypy.response
+
+
+class NullResponse:
+ pass
+
+
started = False
def startup(req=None):
"""Start the CherryPy app server in 'serverless' mode (for WSGI)."""
@@ -220,6 +245,16 @@ def startup(req=None):
cherrypy.server.start(init_only=True, server_class=None)
return 0 # apache.OK
+def startup_null(req=None):
+ """Start the CherryPy app server in NULL 'serverless' mode (for WSGI)."""
+ global started
+ if not started:
+ started = True
+ cherrypy.server.request_class = NullRequest
+ cherrypy.server.response_class = NullResponse
+ cherrypy.server.start(init_only=True, server_class=None)
+ return 0 # apache.OK
+
if __name__ == '__main__':
if "-notests" in sys.argv:
@@ -241,10 +276,18 @@ if __name__ == '__main__':
if "-modpython" in sys.argv:
try:
mpconf = os.path.join(curdir, "bench_mp.conf")
- read_process("apache", "-k start -f %s" % mpconf)
+ if "-null" in sys.argv:
+ # Pass the null option through Apache
+ read_process("apache", "-k start -D nullreq -f %s" % mpconf)
+ else:
+ read_process("apache", "-k start -f %s" % mpconf)
run()
finally:
os.popen("apache -k stop")
else:
+ if "-null" in sys.argv:
+ cherrypy.server.request_class = NullRequest
+ cherrypy.server.response_class = NullResponse
+
# This will block
cherrypy.server.start_with_callback(run)