Browse Source

Merge branch '895'

James Yen 11 years ago
parent
commit
c74c91d800

+ 1 - 0
config/requirements.txt

@@ -1,3 +1,4 @@
+circus
 mysqlclient==1.3.1
 PyMySQL==0.6.2
 psycopg2==2.5.3

+ 7 - 0
flask/app.py

@@ -166,6 +166,13 @@ def plaintext():
     return response
 
 
+try:
+    import meinheld
+    meinheld.server.set_access_logger(None)
+    meinheld.set_keepalive(120)
+except ImportError:
+    pass
+
 # entry point for debugging
 if __name__ == "__main__":
     app.run(debug=True)

+ 7 - 7
flask/benchmark_config

@@ -16,7 +16,7 @@
       "framework": "flask",
       "language": "Python",
       "orm": "Full",
-      "platform": "Gunicorn/Meinheld",
+      "platform": "Meinheld",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
@@ -37,7 +37,7 @@
       "framework": "flask",
       "language": "Python",
       "orm": "Raw",
-      "platform": "Gunicorn/Meinheld",
+      "platform": "Meinheld",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
@@ -60,7 +60,7 @@
       "framework": "flask",
       "language": "Python",
       "orm": "Full",
-      "platform": "Gunicorn/Meinheld",
+      "platform": "Meinheld",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
@@ -83,12 +83,12 @@
       "framework": "flask",
       "language": "Python",
       "orm": "Full",
-      "platform": "Gunicorn/Tornado",
+      "platform": "Tornado",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "flask-pypy",
-      "notes": "PyPy 2.2",
+      "notes": "PyPy 2.3",
       "versus": "wsgi"
     },
     "pypy-mysql-raw": {
@@ -104,12 +104,12 @@
       "framework": "flask",
       "language": "Python",
       "orm": "Raw",
-      "platform": "Gunicorn/Tornado",
+      "platform": "Tornado",
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "flask-pypy-raw",
-      "notes": "PyPy 2.2",
+      "notes": "PyPy 2.3",
       "versus": "wsgi"
     },
     "nginx-uwsgi": {

+ 1 - 0
flask/requirements.txt

@@ -0,0 +1 @@
+Chaussette

+ 26 - 0
flask/serve_tornado.py

@@ -0,0 +1,26 @@
+import tornado.ioloop
+import tornado.web
+import tornado.wsgi
+import tornado.options
+from tornado.options import options
+import tornado.httpserver
+
+tornado.options.define('port', default=8080, type=int, help="Server port")
+tornado.options.define('procs', default=0, type=int, help="Number of processes (default: autodetect)")
+
+
+import app
+wsgiapp = tornado.wsgi.WSGIContainer(app.app.wsgi_app)
+
+import logging
+access_logger = logging.getLogger('tornado.access')
+access_logger.propergate = False
+access_logger.setLevel(logging.WARNING)
+
+
+if __name__ == "__main__":
+    tornado.options.parse_command_line()
+    server = tornado.httpserver.HTTPServer(wsgiapp)
+    server.bind(options.port)
+    server.start(options.procs)
+    tornado.ioloop.IOLoop.instance().start()

+ 28 - 14
flask/setup.py

@@ -6,24 +6,38 @@ 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 app.app
+use_sockets = True
+numprocesses = {PROCS}
+
+[socket:app]
+host = 0.0.0.0
+port = 8080
+"""
+
+proc = None
 
 def start(args, logfile, errfile):
+    global proc
+
+    subprocess.check_call(bin_dir + "/pip install -r requirements.txt",
+                          cwd="flask", stderr=errfile, stdout=logfile, shell=True)
+
+    with open("flask/circus.ini", "w") as f:
+        f.write(CIRCUS_INI.format(BIN=bin_dir, PROCS=NCPU*3))
+
     setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
-    subprocess.Popen([
-        bin_dir + "/gunicorn",
-        "app:app",
-        "-k", "meinheld.gmeinheld.MeinheldWorker",
-        "-b", "0.0.0.0:8080",
-        '-w', str(NCPU*3),
-        "--log-level=critical"],
-        cwd="flask", stderr=errfile, stdout=logfile)
+    proc = subprocess.Popen([bin_dir + "/circusd", "circus.ini"],
+		            cwd="flask", stderr=errfile, stdout=logfile)
     return 0
 
 def stop(logfile, errfile):
-    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
-    out, err = p.communicate()
-    for line in out.splitlines():
-      if 'FrameworkBenchmarks/installs/py2/bin/' in line:
-        pid = int(line.split(None,2)[1])
-        os.kill(pid, 15)
+    global proc
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc.wait()
+    proc = None
     return 0

+ 24 - 9
flask/setup_py3.py

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

+ 4 - 6
flask/setup_pypy.py

@@ -13,15 +13,13 @@ def start(args, logfile, errfile):
     global proc
     setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
     proc = subprocess.Popen([
-        bin_dir + "/gunicorn",
-        "app:app",
-        '-k', 'tornado',
-        "-b", "0.0.0.0:8080",
-        '-w', str(NCPU*3),
-        "--log-level=critical"],
+        bin_dir + "/pypy", "serve_tornado.py",
+        "--port=8080",
+        "--procs="+ str(NCPU*3)],
         cwd="flask", stderr=errfile, stdout=logfile)
     return 0
 
+
 def stop(logfile, errfile):
     global proc
     if proc is None:

+ 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*2))
+
+    proc = subprocess.Popen([bin_dir + "/circusd", "circus.ini"],
+		            cwd="wsgi", stderr=errfile, stdout=logfile)
     return 0
 
 def stop(logfile, errfile):