Browse Source

Merge branch 'master' of https://github.com/purge/FrameworkBenchmarks into purge-master

Patrick Falls 12 years ago
parent
commit
43f8efc82e

+ 23 - 0
web-simple/README.md

@@ -0,0 +1,23 @@
+# Setup
+
+* Perl 5.10+
+* MySQL 5.5
+* Wrk 2.0
+
+# Requirements
+
+* Web::Simple
+* DBD::pg
+* Starman (if using Starman as web server)
+* Plack (for plackup)
+* nginx (if you want to front Dancer with nginx, nginx.conf provided)
+
+# Deployment
+
+Something along the lines of
+
+    plackup -E production -s Starman --workers=8 -l /tmp/frameworks-benchmark.sock -a ./app.pl
+
+if you want to front it with nginx, otherwise
+
+    plackup -E production -s Starman --port=8080 --workers=8 -a ./app.pl

+ 0 - 0
web-simple/__init__.py


+ 32 - 0
web-simple/app.pl

@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+use Web::Simple;
+use JSON::XS;
+use DBI;
+
+my $dsn = "dbi:mysql:database=hello_world;host=localhost";
+my $dbh = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', { RaiseError => 1 });
+my $sth = $dbh->prepare('SELECT * FROM World where id = ?');
+
+sub dispatch_request {
+ sub (/json) {
+    [ 200, [ 'Content-type' => 'application/json', ],
+      [ encode_json({ message => 'Hello, World!' }) ] ];
+  },
+  sub (/db + ?queries~) {
+    my ($self, $queries) = @_;
+    $queries ||= 1;
+    my $rand;
+    my @response;
+    for ( 1 .. $queries ) {
+        my $id = int(rand 10000) + 1;
+        $sth->execute($id);
+        $sth->bind_col(2, \$rand);
+        if ( my @row = $sth->fetch ) {
+          push @response, { id => $id, randomNumber => $rand };
+        }
+    }
+    [ 200, [ 'Content-type' => 'application/json', ], [ encode_json(\@response)] ];
+  }
+}
+
+__PACKAGE__->run_if_script;

+ 18 - 0
web-simple/benchmark_config

@@ -0,0 +1,18 @@
+{
+  "framework": "Web-Simple",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "port": 8080,
+      "sort": 78
+    },
+    "raw": {
+      "setup_file": "setup",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 79
+    }
+  }]
+}

+ 3 - 0
web-simple/conf/config.pl

@@ -0,0 +1,3 @@
+{
+    modules => ['JSON::XS']
+}

+ 37 - 0
web-simple/nginx.conf

@@ -0,0 +1,37 @@
+user USR;
+
+worker_processes 2;
+
+events {
+  worker_connections  1024;
+}
+
+http {
+  output_buffers   1 32k;
+  postpone_output  1460;
+
+  sendfile         on;
+  tcp_nopush       on;
+
+  tcp_nodelay      on;
+
+  upstream backendurl {
+    server unix:/home/ubuntu/FrameworkBenchmarks/web-simple/frameworks-benchmark.sock;
+  }
+
+  server {
+    listen 8080;
+    server_name localhost;
+
+    location / {
+      try_files $uri @proxy;
+      access_log off;
+      expires max;
+    }
+
+    location @proxy {
+      proxy_set_header Host $http_host;
+      proxy_pass http://backendurl;
+    }
+  }
+}

+ 32 - 0
web-simple/setup.py

@@ -0,0 +1,32 @@
+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("web-simple/app.pl", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("web-simple/nginx.conf", "USR", getpass.getuser())
+  setup_util.replace_text("web-simple/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + home + "/FrameworkBenchmarks")
+
+  try:
+    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l " + home + "/FrameworkBenchmarks/web-simple/frameworks-benchmark.sock -a ./app.pl", shell=True, cwd="web-simple")
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/web-simple/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 'starman' in line:
+        pid = int(line.split(None, 2)[1])
+        os.kill(pid, 9)
+    return 0
+  except subprocess.CalledProcessError:
+    return 1