Browse Source

wsgi: Gunicorn => Chaussette

plaintext: 21k req/sec => 114k req/sec
INADA Naoki 11 years ago
parent
commit
74f20abcac
4 changed files with 33 additions and 11 deletions
  1. 1 1
      wsgi/benchmark_config
  2. 10 2
      wsgi/hello.py
  3. 2 0
      wsgi/requirements.txt
  4. 20 8
      wsgi/setup.py

+ 1 - 1
wsgi/benchmark_config

@@ -12,7 +12,7 @@
       "framework": "wsgi",
       "language": "Python",
       "orm": "Raw",
-      "platform": "Gunicorn/Meinheld",
+      "platform": "Meinheld",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",

+ 10 - 2
wsgi/hello.py

@@ -15,7 +15,7 @@ def json(environ, start_response):
         ('Content-type', 'application/json'),
         ('Content-Length', str(len(data)))
     ]
-    start_response('200 OK', response_headers)
+    start_response(b'200 OK', response_headers)
     return [data]
 
 def plaintext(environ, start_response):
@@ -24,7 +24,7 @@ def plaintext(environ, start_response):
         ('Content-type', 'text/plain'),
         ('Content-Length', str(len(data)))
     ]
-    start_response('200 OK', response_headers)
+    start_response(b'200 OK', response_headers)
     return [data]
 
 def app(environ, start_response):
@@ -33,3 +33,11 @@ def app(environ, start_response):
         return json(environ, start_response)
     else:
         return plaintext(environ, start_response)
+
+
+try:
+    import meinheld
+    meinheld.server.set_access_logger(None)
+    meinheld.set_keepalive(120)
+except ImportError:
+    pass

+ 2 - 0
wsgi/requirements.txt

@@ -1 +1,3 @@
 ujson
+circus
+Chaussette

+ 20 - 8
wsgi/setup.py

@@ -6,19 +6,31 @@ import os
 bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
 NCPU = multiprocessing.cpu_count()
 
+CIRCUS_INI = """\
+[watcher:app]
+cmd = {BIN}/chaussette --fd=$(circus.sockets.app) --backend=meinheld hello.app
+use_sockets = True
+numprocesses = {PROCS}
+
+[socket:app]
+host = 0.0.0.0
+port = 8080
+"""
+
 proc = None
 
 
 def start(args, logfile, errfile):
     global proc
-    proc = subprocess.Popen([
-        bin_dir + "/gunicorn",
-        "hello:app",
-        "-k", "meinheld.gmeinheld.MeinheldWorker",
-        "-b", "0.0.0.0:8080",
-        '-w', str(NCPU),
-        "--log-level=critical"],
-        cwd="wsgi", stderr=errfile, stdout=logfile)
+
+    subprocess.check_call(bin_dir + "/pip install -r requirements.txt",
+                          cwd="wsgi", stderr=errfile, stdout=logfile, shell=True)
+
+    with open("wsgi/circus.ini", "w") as f:
+        f.write(CIRCUS_INI.format(BIN=bin_dir, PROCS=NCPU*3))
+
+    proc = subprocess.Popen([bin_dir + "/circusd", "circus.ini"],
+		            cwd="wsgi", stderr=errfile, stdout=logfile)
     return 0
 
 def stop(logfile, errfile):