Browse Source

Merge remote-tracking branch 'origin/master' into run-all-test-in-directory

INADA Naoki 11 years ago
parent
commit
1195dd771e

+ 6 - 0
.travis.yml

@@ -176,3 +176,9 @@ notifications:
     on_failure: always
     skip_join: true
 
+cache:
+  directories:
+    - installs/mono-3.2.8
+    - installs/py2
+    - installs/py3
+    - installs/perl-5.18

+ 5 - 0
dancer/bash_profile.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+export PERL_HOME=${IROOT}/perl-5.18
+
+export PATH="$PERL_HOME/bin:$PATH"

+ 4 - 1
dancer/install.sh

@@ -1,3 +1,6 @@
 #!/bin/bash
 
-fw_depends perl
+fw_depends perl nginx
+
+cpanm --notest --no-man-page Dancer Dancer::Plugin::Database DBI DBD::mysql JSON::XS Plack Starman
+echo installed Dancer app dependencies

+ 2 - 1
dancer/nginx.conf

@@ -1,4 +1,5 @@
-user tfb;
+# Replaced by setup.py
+user USR;
 error_log stderr error;
 
 worker_processes 2;

+ 4 - 6
dancer/setup.py

@@ -5,16 +5,14 @@ from os.path import expanduser
 import os
 import getpass
 
-home = expanduser("~")
-
 def start(args, logfile, errfile):
-  setup_util.replace_text("dancer/app.pl", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("dancer/app.pl", "localhost", args.database_host)
   setup_util.replace_text("dancer/nginx.conf", "USR", getpass.getuser())
-  setup_util.replace_text("dancer/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + home + "/FrameworkBenchmarks")
+  setup_util.replace_text("dancer/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + args.fwroot)
 
   try:
-    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l " + home + "/FrameworkBenchmarks/dancer/frameworks-benchmark.sock -a ./app.pl", shell=True, cwd="dancer", stderr=errfile, stdout=logfile)
-    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/dancer/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l $TROOT/frameworks-benchmark.sock -a ./app.pl", shell=True, cwd="dancer", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1

+ 25 - 9
kelp/README.md

@@ -6,18 +6,34 @@
 
 # Requirements
 
-* Kelp
-* DBD::mysql
-* Starman (if using Starman as web server)
-* Plack (for plackup)
-* nginx (if you want to front Dancer with nginx, nginx.conf provided)
+* Kelp (install from CPAN)
+* Kelp::Module::JSON::XS (install from CPAN)
+* DBD::mysql (install from CPAN)
+* Starman (install from CPAN)
+* nginx (if you want to front with nginx, nginx.conf provided)
 
 # Deployment
 
-Something along the lines of
+## uWSGI (Recommended)
 
-    plackup -E production -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl
+1. Create a configuration file. Bare bones example of app.ini:
 
-if you want to front it with nginx, otherwise
+    [uwsgi]
+    http-socket = :8080
+    psgi = app.pl
 
-    plackup -E production -s Starman --port=8080 --workers=2 -a ./app.pl
+2. Make sure you have installed the psgi plugin.
+
+3. Deploy with uwsgi
+
+    uwsgi --http-modifier1 5 --plugin psgi --ini app.ini
+
+## Plack + Starman
+
+1. Deploy via plackup
+
+    plackup -E production -s Starman --workers=5 -l /tmp/frameworks-benchmark.sock -a ./app.pl
+
+2. If you want to front it with nginx, otherwise
+
+    plackup -E production -s Starman --port=8080 --workers=5 -a ./app.pl

+ 62 - 10
kelp/app.pl

@@ -2,23 +2,77 @@
 use Kelp::Less;
 use DBI;
 
-my $dsn = "dbi:mysql:database=hello_world;host=localhost;port=3306";
-my $dbh = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
-my $sth = $dbh->prepare("SELECT * FROM World where id = ?");
+my $dsn  = "dbi:mysql:database=hello_world;host=localhost;port=3306";
+my $dbh  = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
+my $sth  = $dbh->prepare("SELECT * FROM World WHERE id = ?");
+my $sth1 = $dbh->prepare("SELECT * FROM Fortune");
+my $sth2 = $dbh->prepare("UPDATE World SET randomNumber = ? WHERE id = ?");
+
+get '/populate' => sub {
+    $dbh->do("DELETE FROM World");
+    $dbh->do("DELETE FROM Fortune");
+    srand;
+
+    # Add some random numbers
+    my @rand = map {'(' . $_ . ',' . int(rand(10_000)) . ')'} (1 .. 10_000);
+    $dbh->do(q[INSERT INTO World (id, randomNumber) VALUES ] . join(',', @rand));
+
+    # Add some fortunes
+    my @fortunes = map { '("' . 'x' x (int(rand(20)) + 1) . '")' } (1 .. 30);
+    $dbh->do(q[INSERT INTO Fortune (message) VALUES ] . join(',', @fortunes));
+
+    "OK";
+};
 
 get '/json' => sub {
-    { message => 'Hello, World!' }
+    my $self = shift;
+    { message => 'Hello, World!' };
 };
 
 get '/db' => sub {
+    query(1);
+};
+
+get '/queries' => sub {
+    my $self = shift;
+    my $count = $self->param('queries') || 1;
+    query( $count > 500 ? 500 : $count );
+};
+
+get '/fortunes' => sub {
     my $self = shift;
-    my $queries = $self->param('queries') || 1;
+    $sth1->execute();
+    my $fortunes = $sth1->fetchall_arrayref({});
+    $self->template( 'fortunes', { fortunes => $fortunes } );
+};
+
+get '/updates' => sub {
+    my $self  = shift;
+    my $count = $self->param('queries');
+    my $arr   = query( $count > 500 ? 500 : $count );
+    for my $row (@$arr) {
+        $row->{randomNumber} = int( rand(10_000) ) + 1;
+        $sth2->execute( $row->{randomNumber}, $row->{id} );
+    }
+
+    $arr;
+};
+
+get '/plaintext' => sub {
+    my $self = shift;
+    $self->res->text->render('Hello, World!');
+};
+
+run;
+
+sub query {
+    my $count = shift;
     my @response;
-    for ( 1 .. $queries ) {
+    for ( 1 .. $count ) {
         my $id = int rand 10000 + 1;
         $sth->execute($id);
         if ( my $row = $sth->fetchrow_hashref ) {
-            if ( $queries == 1 ) {
+            if ( $count == 1 ) {
                 return { id => $id, randomNumber => $row->{randomNumber} };
             }
             else {
@@ -28,6 +82,4 @@ get '/db' => sub {
         }
     }
     return \@response;
-};
-
-run;
+}

+ 5 - 0
kelp/bash_profile.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+export PERL_HOME=${IROOT}/perl-5.18
+
+export PATH="$PERL_HOME/bin:$PATH"

+ 6 - 20
kelp/benchmark_config

@@ -4,32 +4,18 @@
     "default": {
       "setup_file": "setup",
       "json_url": "/json",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Fullstack",
-      "database": "None",
-      "framework": "kelp",
-      "language": "Perl",
-      "orm": "Full",
-      "platform": "Plack",
-      "webserver": "Starman",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "kelp",
-      "notes": "",
-      "versus": ""
-    },
-    "raw": {
-      "setup_file": "setup",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortune",
+      "update_url": "/update?queries=",
+      "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",
       "database": "MySQL",
       "framework": "kelp",
       "language": "Perl",
-      "orm": "Raw",
+      "orm": "Full",
       "platform": "Plack",
       "webserver": "Starman",
       "os": "Linux",
@@ -39,4 +25,4 @@
       "versus": ""
     }
   }]
-}
+}

+ 1 - 1
kelp/conf/config.pl

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

+ 4 - 1
kelp/install.sh

@@ -1,3 +1,6 @@
 #!/bin/bash
 
-fw_depends perl
+fw_depends perl nginx
+
+cpanm --notest --no-man-page Kelp DBI DBD::mysql Kelp::Module::JSON::XS Plack Starman
+echo installed Kelp app dependencies

+ 2 - 1
kelp/nginx.conf

@@ -1,4 +1,5 @@
-user tfb;
+# Replaced by setup.py
+user USR;
 error_log stderr error;
 
 worker_processes 2;

+ 4 - 6
kelp/setup.py

@@ -5,16 +5,14 @@ from os.path import expanduser
 import os
 import getpass
 
-home = expanduser("~")
-
 def start(args, logfile, errfile):
-  setup_util.replace_text("kelp/app.pl", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("kelp/app.pl", "localhost", args.database_host)
   setup_util.replace_text("kelp/nginx.conf", "USR", getpass.getuser())
-  setup_util.replace_text("kelp/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + home + "/FrameworkBenchmarks")
+  setup_util.replace_text("kelp/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + args.fwroot)
 
   try:
-    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l " + home + "/FrameworkBenchmarks/kelp/frameworks-benchmark.sock -a ./app.pl", shell=True, cwd="kelp", stderr=errfile, stdout=logfile)
-    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/kelp/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l $TROOT/frameworks-benchmark.sock -a $TROOT/app.pl", shell=True, cwd="kelp", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1

+ 10 - 0
kelp/views/fortunes.tt

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+[% FOREACH item IN fortunes  %]<tr><td>[% item.id %]</td><td>[% item.message %]</td></tr>[% END %]
+</table>
+</body>
+</html>

+ 1 - 6
mojolicious/install.sh

@@ -2,10 +2,5 @@
 
 fw_depends perl
 
-# Ensure Mango and Mojolicious are installed
-fw_get http://cpanmin.us -O cpanminus.pl
-echo Got cpanm
-perl-5.18/bin/perl cpanminus.pl --notest --no-man-page App::cpanminus
-echo installed cpanm
-perl-5.18/bin/cpanm --notest --no-man-page --installdeps ../mojolicious
+cpanm --notest --no-man-page --installdeps $TROOT
 echo installed Mojolicious app dependencies

+ 3 - 10
mojolicious/setup.py

@@ -14,22 +14,15 @@ def start(args, logfile, errfile):
 
   try:
     # os.environ["MOJO_MODE"] = "production"
-    subprocess.Popen("hypnotoad ./app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
+    subprocess.Popen("hypnotoad $TROOT/app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1
 
 def stop(logfile, errfile):
   try:
-    subprocess.call("hypnotoad -s ./app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
-    #p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
-    #out, err = p.communicate()
-    #for line in out.splitlines():
-    #  if 'hypnotoad' in line:
-    #    pid = int(line.split(None, 2)[1])
-    #    os.kill(pid, 15)
+    subprocess.call("hypnotoad -s $TROOT/app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
     return 0
-  except subprocess.CalledProcessError as e:
-    print e
+  except subprocess.CalledProcessError:
     return 1
 

+ 5 - 0
plack/bash_profile.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+export PERL_HOME=${IROOT}/perl-5.18
+
+export PATH="$PERL_HOME/bin:$PATH"

+ 4 - 1
plack/install.sh

@@ -1,3 +1,6 @@
 #!/bin/bash
 
-fw_depends perl
+fw_depends perl nginx
+
+cpanm --notest --no-man-page --installdeps $TROOT
+echo installed Plack app dependencies

+ 2 - 0
plack/nginx.conf

@@ -1,3 +1,5 @@
+# Replaced by setup.py
+user USR;
 error_log stderr error;
 pid        /tmp/nginx.pid;
 worker_processes 4;

+ 6 - 10
plack/setup.py

@@ -5,24 +5,20 @@ from os.path import expanduser
 import os
 import getpass
 
-home = expanduser("~")
-
 def start(args, logfile, errfile):
-  setup_util.replace_text("plack/app.psgi", "localhost", ""+ args.database_host +"")
+  setup_util.replace_text("plack/app.psgi", "localhost", args.database_host)
   setup_util.replace_text("plack/nginx.conf", "USR", getpass.getuser())
-  setup_util.replace_text("plack/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + home + "/FrameworkBenchmarks")
+  setup_util.replace_text("plack/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + args.fwroot)
   try:
-    subprocess.check_call("curl -L http://cpanmin.us | perl - App::cpanminus", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
-    subprocess.check_call("cpanm --notest --no-man-pages --installdeps "+home+"/FrameworkBenchmarks/plack", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
-    subprocess.Popen("start_server --backlog=16384 --pid-file="+home+"/FrameworkBenchmarks/plack/app.pid --path="+home+"/FrameworkBenchmarks/plack/app.sock -- plackup -E production -s Starlet --max-keepalive-reqs 1000 --max-reqs-per-child 50000 --min-reqs-per-child 40000 --max-workers=" + str(args.max_threads+4) + " -a "+home+"/FrameworkBenchmarks/plack/app.psgi", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
-    subprocess.check_call("/usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/plack/nginx.conf", shell=True,stderr=errfile, stdout=logfile)
+    subprocess.Popen("start_server --backlog=16384 --pid-file=$TROOT/app.pid --path=$TROOT/app.sock -- plackup -E production -s Starlet --max-keepalive-reqs 1000 --max-reqs-per-child 50000 --min-reqs-per-child 40000 --max-workers=" + str(args.max_threads+4) + " -a $TROOT/app.psgi", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf", shell=True,stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1
 def stop(logfile, errfile):
   try:
-    subprocess.call('kill -TERM $(cat '+home+"/FrameworkBenchmarks/plack/app.pid)", shell=True, stderr=errfile, stdout=logfile)
-    subprocess.call("/usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/plack/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.call('kill -TERM $(cat $TROOT/app.pid)', shell=True, stderr=errfile, stdout=logfile)
+    subprocess.call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1

+ 5 - 2
toolset/setup/linux/languages/perl.sh

@@ -3,9 +3,12 @@
 RETCODE=$(fw_exists perl-5.18)
 [ ! "$RETCODE" == 0 ] || { return 0; }
 
-fw_get https://raw.githubusercontent.com/tokuhirom/Perl-Build/72587c8a13c3cd7f26fd25d6243a89d7a0327b1d/perl-build -O perl-build.pl
+fw_get https://raw.github.com/tokuhirom/Perl-Build/master/perl-build -O perl-build.pl
+# compile with optimizations, n.b. this does not turn on debugging
 perl perl-build.pl -DDEBUGGING=-g 5.18.2 perl-5.18
 
 fw_get http://cpanmin.us -O cpanminus.pl
 perl-5.18/bin/perl cpanminus.pl --notest --no-man-page App::cpanminus
-perl-5.18/bin/cpanm -f --notest --no-man-page DBI DBD::mysql Kelp Dancer Mojolicious Mango Kelp::Module::JSON::XS Dancer::Plugin::Database Starman Plack JSON Web::Simple DBD::Pg JSON::XS EV HTTP::Parser::XS Monoceros EV IO::Socket::IP IO::Socket::SSL Memoize
+# Install only a bare-bones of Perl modules
+# Install others in the per-framework install script or cpanfile
+perl-5.18/bin/cpanm -f --notest --no-man-page JSON JSON::XS IO::Socket::IP IO::Socket::SSL

+ 1 - 1
web-simple/README.md

@@ -7,7 +7,7 @@
 # Requirements
 
 * Web::Simple
-* DBD::pg
+* DBD::mysql
 * Starman (if using Starman as web server)
 * Plack (for plackup)
 * nginx (if you want to front Dancer with nginx, nginx.conf provided)

+ 5 - 0
web-simple/bash_profile.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+export PERL_HOME=${IROOT}/perl-5.18
+
+export PATH="$PERL_HOME/bin:$PATH"

+ 4 - 1
web-simple/install.sh

@@ -1,3 +1,6 @@
 #!/bin/bash
 
-fw_depends perl
+fw_depends perl nginx
+
+cpanm --notest --no-man-page Web::Simple DBI DBD::mysql Plack Starman JSON::XS
+echo installed Web::Simple app dependencies

+ 2 - 1
web-simple/nginx.conf

@@ -1,4 +1,5 @@
-user tfb;
+# Replaced by setup.py
+user USR;
 error_log stderr error;
 
 worker_processes 2;

+ 4 - 6
web-simple/setup.py

@@ -5,16 +5,14 @@ from os.path import expanduser
 import os
 import getpass
 
-home = expanduser("~")
-
 def start(args, logfile, errfile):
-  setup_util.replace_text("web-simple/app.pl", "localhost", ""+ args.database_host +"")
+  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")
+  setup_util.replace_text("web-simple/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + args.fwroot)
 
   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", stderr=errfile, stdout=logfile)
-    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/web-simple/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.Popen("plackup -E production -s Starman --workers=" + str(args.max_threads) + " -l $TROOT/frameworks-benchmark.sock -a $TROOT/app.pl", shell=True, cwd="web-simple", stderr=errfile, stdout=logfile)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1