Browse Source

Add django-postgresql benchmark.

INADA Naoki 12 years ago
parent
commit
941b7f8f7b
6 changed files with 61 additions and 6 deletions
  1. 10 0
      django/benchmark_config
  2. 6 4
      django/hello/hello/settings.py
  3. 5 2
      django/hello/world/models.py
  4. 2 0
      django/setup.py
  5. 36 0
      django/setup_pg.py
  6. 2 0
      installer.py

+ 10 - 0
django/benchmark_config

@@ -20,6 +20,16 @@
       "update_url": "/update?queries=",
       "port": 8080,
       "sort": 242
+    },
+    "postgresql": {
+      "setup_file": "setup_pg",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/update?queries=",
+      "port": 8080,
+      "sort": 245
     }
   }]
 }

+ 6 - 4
django/hello/hello/settings.py

@@ -1,5 +1,7 @@
 # Django settings for hello project.
 
+import os
+
 DEBUG = False
 TEMPLATE_DEBUG = DEBUG
 
@@ -11,10 +13,10 @@ MANAGERS = ADMINS
 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': 'hello_world',                      # Or path to database file if using sqlite3.
-        'USER': 'benchmarkdbuser',                      # Not used with sqlite3.
-        'PASSWORD': 'benchmarkdbpass',                  # Not used with sqlite3.
+        'ENGINE': 'django.db.backends.' + os.environ['DJANGO_DB'], # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+        'NAME': 'hello_world',           # Or path to database file if using sqlite3.
+        'USER': 'benchmarkdbuser',       # Not used with sqlite3.
+        'PASSWORD': 'benchmarkdbpass',   # Not used with sqlite3.
         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
         'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
         'CONN_MAX_AGE': 30,

+ 5 - 2
django/hello/world/models.py

@@ -1,13 +1,16 @@
 from django.db import models
 
+import os
+MYSQL = os.environ['DJANGO_DB'] == 'mysql'
+
 # Create your models here.
 
 class World(models.Model):
   randomnumber = models.IntegerField()
   class Meta:
-    db_table = 'World'
+    db_table = 'World' if MYSQL else 'world'
 
 class Fortune(models.Model):
   message = models.CharField(max_length=65535)
   class Meta:
-    db_table = 'Fortune'
+    db_table = 'Fortune' if MYSQL else 'fortune'

+ 2 - 0
django/setup.py

@@ -14,6 +14,8 @@ def start(args):
     global proc
     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)
+    env = os.environ.copy()
+    env['DJANGO_DB'] = 'mysql'
     proc = subprocess.Popen([
         bin_dir + "/gunicorn",
         "hello.wsgi:application",

+ 36 - 0
django/setup_pg.py

@@ -0,0 +1,36 @@
+import subprocess
+import setup_util
+import multiprocessing
+import os
+
+home = os.path.expanduser('~')
+bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
+NCPU = multiprocessing.cpu_count()
+
+proc = None
+
+
+def start(args):
+    global proc
+    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)
+    env = os.environ.copy()
+    env['DJANGO_DB'] = 'postgresql_psycopg2'
+    proc = subprocess.Popen([
+        bin_dir + "/gunicorn",
+        "hello.wsgi:application",
+        "-k", "meinheld.gmeinheld.MeinheldWorker",
+        "-b", "0.0.0.0:8080",
+        '-w', str(NCPU*3),
+        "--log-level=critical"],
+        cwd="django/hello")
+    return 0
+
+def stop():
+    global proc
+    if proc is None:
+        return 0
+    proc.terminate()
+    proc.wait()
+    proc = None
+    return 0

+ 2 - 0
installer.py

@@ -325,6 +325,8 @@ class Installer:
                  two=False, three=True, pypy=False)
     easy_install('PyMySQL==0.5', pypy=True)
     easy_install('PyMySQL3==0.5', two=False, three=True)
+    easy_install('psycopg2==2.5.1', three=True)
+
     easy_install('simplejson==3.3.0', two=True, three=True, pypy=False)
     easy_install('ujson==1.33', three=True)
     easy_install('https://github.com/downloads/surfly/gevent/gevent-1.0rc2.tar.gz', three=True)