Browse Source

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

Patrick Falls 12 years ago
parent
commit
56df0d9cea
10 changed files with 301 additions and 0 deletions
  1. 24 0
      dancer/README.md
  2. 28 0
      dancer/app.pl
  3. 37 0
      dancer/nginx.conf
  4. 23 0
      kelp/README.md
  5. 29 0
      kelp/app.pl
  6. 37 0
      kelp/nginx.conf
  7. 32 0
      mojolicious/README.md
  8. 31 0
      mojolicious/app.pl
  9. 37 0
      mojolicious/nginx.conf
  10. 23 0
      plack/app.psgi

+ 24 - 0
dancer/README.md

@@ -0,0 +1,24 @@
+# Setup
+
+* Perl 5.16.3
+* MySQL 5.5
+* Wrk 2.0
+
+# Requirements
+
+* Dancer
+* Dancer::Plugin::Database
+* DBD::mysql
+* 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=2 -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=2 -a ./app.pl

+ 28 - 0
dancer/app.pl

@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Dancer ':syntax';
+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' });
+
+get '/json' => sub {
+    { message => 'Hello, World!' }
+};
+
+get '/db' => sub {
+    my $queries = params->{queries} || 1;
+    my @response;
+    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} };
+        }
+    }
+    { \@response }
+};
+
+Dancer->dance;

+ 37 - 0
dancer/nginx.conf

@@ -0,0 +1,37 @@
+user www;
+
+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:/tmp/frameworks-benchmark.sock;
+  }
+
+  server {
+    listen 8888;
+    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;
+    }
+  }
+}

+ 23 - 0
kelp/README.md

@@ -0,0 +1,23 @@
+# Setup
+
+* Perl 5.10+
+* MySQL 5.5
+* Wrk 2.0
+
+# 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)
+
+# Deployment
+
+Something along the lines of
+
+    plackup -E production -s Starman --workers=2 -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=2 -a ./app.pl

+ 29 - 0
kelp/app.pl

@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use Kelp::Less;
+use DBI;
+
+attr dbh => sub {
+    my $database = 'test';
+    my $host     = 'ip-10-34-150-134.eu-west-1.compute.internal';
+    my $dsn      = 'dbi:mysql:database=$database;host=$host;port=3306';
+    DBI->connect( $dsn, 'root', '', {} );
+};
+
+get '/json' => sub {
+    { message => 'Hello, World!' }
+};
+
+get '/db' => sub {
+    my $self = shift;
+    my $queries = param->{queries} || 1;
+    my @response;
+    for( 1 .. $queries ) {
+        my $id = int rand 10000 + 1;
+        if ( my $row = $self->dbh->quick_select( 'world', { id => $id } ) ) {
+            push @response, { id => $id, randomNumber => $row->{randomnumber} };
+        }
+    }
+    { \@response }
+};
+
+run;

+ 37 - 0
kelp/nginx.conf

@@ -0,0 +1,37 @@
+user www;
+
+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:/tmp/frameworks-benchmark.sock;
+  }
+
+  server {
+    listen 8888;
+    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
mojolicious/README.md

@@ -0,0 +1,32 @@
+# Setup
+
+* Perl 5.16.3
+* MySQL 5.5
+* Wrk 2.0
+
+# Requirements
+
+* Mojolicious
+* Mojolicious::Plugin::Database
+* DBD::mysql
+* Starman (if using Starman as web server)
+* Plack (for plackup)
+* nginx (if you want to front Mojolicious
+with nginx, nginx.conf provided)
+* Morbo and Hypnotoad provided by Mojolicious
+
+# Deployment
+
+Set production mode:
+
+    export MOJO_MODE=production
+
+Something along the lines of
+
+    plackup -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl
+
+if you want to front it with nginx, otherwise
+
+    plackup -s Starman --port 8080 --workers=2 -a ./app.pl
+
+or the equivalent Morbo or Hypnotoad commands.

+ 31 - 0
mojolicious/app.pl

@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+use Mojolicious::Plugin::Database;
+
+plugin 'database', {
+    dsn      => 'dbi:mysql:dbname=test',
+    username => 'root',
+    password => ''
+};
+
+get '/json' => sub {
+    my $self = shift;
+    $self->render( json => { message => 'Hello, world!' } );
+};
+
+get '/db' => sub {
+    my $self = shift;
+    my $queries = $self->param('queries') || 1;
+    my @response;
+    my $sth = $self->db->prepare( 'SELECT randomnumber FROM world WHERE id = ?' );
+    for ( 1 .. $queries ) {
+        my $id = int rand 10000 + 1;
+        my $res = $sth->execute( $id );
+        if ( my $row = $sth->fetchrow_arrayref ) {
+            push @response, { id => $id, randomNumber => $row->[0] };
+        }
+    }
+    $self->render( json => \@response );
+};
+
+app->start;

+ 37 - 0
mojolicious/nginx.conf

@@ -0,0 +1,37 @@
+user www;
+
+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:/tmp/frameworks-benchmark.sock;
+  }
+
+  server {
+    listen 8888;
+    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;
+    }
+  }
+}

+ 23 - 0
plack/app.psgi

@@ -0,0 +1,23 @@
+# plackup -s Starman --workers N -E deployment app.psgi
+# -or-
+# plackup -s Twiggy::Prefork --max_workers N -E deployment app.psgi
+use v5.16;
+use Plack::Builder;
+use Plack::Request;
+use JSON::XS 'encode_json';
+use DBI;
+
+my $dbh = DBI->connect('dbi:mysql:dbname=test', 'root') || die $!;
+my $sth = $dbh->prepare('SELECT randomnumber FROM world WHERE id = ?');
+my $header = ['Content-Type' => 'application/json'];
+
+builder {
+    mount '/json' => sub { [ 200, $header, [ encode_json({ message => 'Hello, World!' })] ] },
+    mount '/dbi' => sub { [ 200, $header, [ encode_json([
+        map { id => $_->[0] + 0, randomnumber => $_->[1] },
+        grep exists $_->[1],
+        map [$_, $sth->execute($_) && $sth->fetchrow_array],
+        map int rand 10000 + 1,
+        1..Plack::Request->new(shift)->param('queries')//1
+    ]) ] ] }
+};