Browse Source

wsgi: Add nginx+uWSGI for 10% perf improvement over gunicorn

nginx+uWSGI can be a killer performance combination as described here:

http://lists.unbit.it/pipermail/uwsgi/2013-September/006431.html
Malcolm Evershed 12 years ago
parent
commit
0880d067f4
1 changed files with 25 additions and 0 deletions
  1. 25 0
      wsgi/setup_nginxuwsgi.py

+ 25 - 0
wsgi/setup_nginxuwsgi.py

@@ -0,0 +1,25 @@
+import subprocess
+import multiprocessing
+import os
+
+bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
+config_dir = os.path.expanduser('~/FrameworkBenchmarks/config')
+NCPU = multiprocessing.cpu_count()
+
+def start(args):
+    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) +
+            ' --wsgi hello:app',
+            shell=True, cwd='wsgi')
+        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