ソースを参照

bottle: add nginx+uWSGI combination for ~9% performance gain above gunicorn

The 9% gain was observed on my setup for the json 256-concurrency test.
Malcolm Evershed 12 年 前
コミット
3bfe52e836
2 ファイル変更38 行追加0 行削除
  1. 11 0
      bottle/benchmark_config
  2. 27 0
      bottle/setup_nginxuwsgi.py

+ 11 - 0
bottle/benchmark_config

@@ -42,6 +42,17 @@
       "update_url": "/raw-updates?queries=",
       "port": 8080,
       "sort": 89
+    },
+    "nginxuwsgi": {
+      "setup_file": "setup_nginxuwsgi",
+      "json_url": "/json",
+      "db_url": "/dbs",
+      "query_url": "/db?queries=",
+      "fortune_url": "/fortune",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "sort": 325
     }
   }]
 }

+ 27 - 0
bottle/setup_nginxuwsgi.py

@@ -0,0 +1,27 @@
+import subprocess
+import multiprocessing
+import os
+import setup_util
+
+bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
+config_dir = os.path.expanduser('~/FrameworkBenchmarks/config')
+NCPU = multiprocessing.cpu_count()
+
+def start(args):
+    setup_util.replace_text("bottle/app.py", "DBHOSTNAME", args.database_host)
+    try:
+        subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c ' +
+            config_dir + '/nginx_uwsgi.conf', shell=True)
+        # Run in the background, but keep stdout/stderr for easy debugging
+        subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
+            ' --processes ' + str(NCPU * 3) +
+            ' --wsgi app:app',
+            shell=True, cwd='bottle')
+        return 0
+    except subprocess.CalledProcessError:
+        return 1
+
+def stop():
+    subprocess.call('sudo /usr/local/nginx/sbin/nginx -s stop', shell=True)
+    subprocess.call(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi_stop.ini', shell=True)
+    return 0