Browse Source

created benchmark_config and setup.py files for dancer

Patrick Falls 12 years ago
parent
commit
8a6ab080c9
6 changed files with 65 additions and 5 deletions
  1. 0 0
      dancer/__init__.py
  2. 2 2
      dancer/app.pl
  3. 19 0
      dancer/benchmark_config
  4. 3 3
      dancer/nginx.conf
  5. 31 0
      dancer/setup.py
  6. 10 0
      installer.py

+ 0 - 0
dancer/__init__.py


+ 2 - 2
dancer/app.pl

@@ -7,7 +7,7 @@ use Dancer::Plugin::Database;
 set serializer => 'JSON';
 
 #my $dbh = database({ driver => 'mysql', database => 'test' });
-my $dbh = database({ driver => 'mysql', host => 'ip-10-34-150-134.eu-west-1.compute.internal', database => 'test', username => 'root' });
+my $dbh = database({ driver => 'mysql', host => 'localhost', database => 'hello_world', username => 'benchmarkdbuser', password => 'benchmarkdbpass' });
 
 get '/json' => sub {
     { message => 'Hello, World!' }
@@ -19,7 +19,7 @@ get '/db' => sub {
     for( 1 .. $queries ) {
         my $id = int rand 10000 + 1;
         if ( my $row = $dbh->quick_select( 'world', { id => $id } ) ) {
-            push @response, { id => $id, randomNumber => $row->{randomnumber} };
+            push @response, { id => $id, randomNumber => $row->{randomNumber} };
         }
     }
     { \@response }

+ 19 - 0
dancer/benchmark_config

@@ -0,0 +1,19 @@
+{
+  "framework": "dancer",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "port": 8080,
+      "sort": 76
+    },
+    "raw": {
+      "setup_file": "setup",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 77
+    }
+  }]
+}
+

+ 3 - 3
dancer/nginx.conf

@@ -1,4 +1,4 @@
-user www;
+user USR;
 
 worker_processes 2;
 
@@ -16,11 +16,11 @@ http {
   tcp_nodelay      on;
 
   upstream backendurl {
-    server unix:/tmp/frameworks-benchmark.sock;
+    server unix:/home/pfalls/FrameworkBenchmarks/dancer/frameworks-benchmark.sock;
   }
 
   server {
-    listen 8888;
+    listen 8080;
     server_name localhost;
 
     location / {

+ 31 - 0
dancer/setup.py

@@ -0,0 +1,31 @@
+import subprocess
+import sys
+import setup_util
+from os.path import expanduser
+import os
+import getpass
+
+home = expanduser("~")
+
+def start(args):
+  setup_util.replace_text("dancer/app.pl", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("dancer/nginx.conf", "USR", getpass.getuser())
+
+  try:
+    subprocess.Popen("plackup -E production -s Starman --workers=2 -l " + home + "/FrameworkBenchmarks/dancer/frameworks-benchmark.sock -a ./app.pl", shell=True, cwd="dancer")
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/dancer/nginx.conf", shell=True)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  try:
+    subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
+    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+    out, err = p.communicate()
+    for line in out.splitlines():
+      if 'plackup' in line:
+        pid = int(line.split(None, 2)[1])
+        os.kill(pid, 9)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1

+ 10 - 0
installer.py

@@ -128,6 +128,16 @@ class Installer:
     self.__run_command("sudo ringo-admin install oberhamsi/reinhardt")
     self.__run_command("sudo ringo-admin install grob/ringo-sqlstore")
 
+    #
+    # Perl
+    #
+    self.__run_command("sudo cpan install Plack", send_yes=True)
+    self.__run_command("sudo cpan install Starman")
+    self.__run_command("sudo cpan install DBD::mysql")
+    self.__run_command("sudo cpan install Dancer")
+    self.__run_command("sudo cpan install Dancer::Plugin::Database")
+    self.__run_command("sudo cpan install JSON", send_yes=True)
+
     #######################################
     # Webservers
     #######################################