Browse Source

django, django-stripped: Tuning worker processes.

INADA Naoki 12 years ago
parent
commit
13a8b5e36d
2 changed files with 6 additions and 8 deletions
  1. 3 3
      django-stripped/setup.py
  2. 3 5
      django/setup.py

+ 3 - 3
django-stripped/setup.py

@@ -1,13 +1,13 @@
-
 import subprocess
+import multiprocessing
 import sys
 import setup_util
 import os
 
 def start(args):
   setup_util.replace_text("django-stripped/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
-
-  subprocess.Popen("gunicorn hello.wsgi:application --worker-class=\"egg:meinheld#gunicorn_worker\" -b 0.0.0.0:8080 -w " + str((args.max_threads * 2)) + " --log-level=critical", shell=True, cwd="django-stripped/hello")
+  subprocess.Popen("gunicorn hello.wsgi:application --worker-class=\"egg:meinheld#gunicorn_worker\" -b 0.0.0.0:8080 -w " +
+                   str((multiprocessing.cpu_count() * 3)) + " --log-level=critical", shell=True, cwd="django-stripped/hello")
   return 0
 def stop():
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)

+ 3 - 5
django/setup.py

@@ -1,4 +1,5 @@
 import subprocess
+import multiprocessing
 import sys
 import setup_util
 import os
@@ -9,11 +10,8 @@ home = expanduser("~")
 def start(args):
   setup_util.replace_text("django/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
   setup_util.replace_text("django/hello/hello/settings.py", "\/home\/ubuntu",  home)
-  # because pooling doesn't work with meinheld, it's necessary to create a ton of gunicorn threads (think apache pre-fork)
-  # to allow the OS to switch processes when waiting for socket I/O.
-  #args.max_threads *= 8
-  # and go from there until the database server runs out of memory for new threads (connections)
-  subprocess.Popen("gunicorn hello.wsgi:application --worker-class=\"egg:meinheld#gunicorn_worker\"  -b 0.0.0.0:8080 -w " + str((args.max_threads * 8)) + " --log-level=critical", shell=True, cwd="django/hello")
+  subprocess.Popen("gunicorn hello.wsgi:application --worker-class=\"egg:meinheld#gunicorn_worker\"  -b 0.0.0.0:8080 -w " +
+                   str((multiprocessing.cpu_count() * 3)) + " --log-level=critical", shell=True, cwd="django/hello")
   return 0
 def stop():
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)