From 78ee98696efe791ec952cc01c821c39a293d909a Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sat, 13 Apr 2013 10:24:02 +0100 Subject: [PATCH 01/11] Dancer (Perl) app --- dancer/app.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 dancer/app.pl diff --git a/dancer/app.pl b/dancer/app.pl new file mode 100755 index 00000000000..93fb2817fa9 --- /dev/null +++ b/dancer/app.pl @@ -0,0 +1,27 @@ +#!/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' }); + +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; From 2e16d7cfe2a176b93a316a2050566bf9a50907c3 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sat, 13 Apr 2013 11:29:53 +0100 Subject: [PATCH 02/11] Mojolicious (Perl) app --- mojolicious/README.mdown | 3 +++ mojolicious/app.pl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 mojolicious/README.mdown create mode 100755 mojolicious/app.pl diff --git a/mojolicious/README.mdown b/mojolicious/README.mdown new file mode 100644 index 00000000000..10a12e86d9f --- /dev/null +++ b/mojolicious/README.mdown @@ -0,0 +1,3 @@ +Start with + + ./app.pl daemon diff --git a/mojolicious/app.pl b/mojolicious/app.pl new file mode 100755 index 00000000000..cdb88546d97 --- /dev/null +++ b/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; From 3c6db3930b53aa509b1e41fcb67dd233d8659547 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 10:18:44 +0100 Subject: [PATCH 03/11] Added nginx configuration file --- dancer/nginx.conf | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dancer/nginx.conf diff --git a/dancer/nginx.conf b/dancer/nginx.conf new file mode 100644 index 00000000000..7e228093bf8 --- /dev/null +++ b/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; + } + } +} From c163ed893b4a22645cb52bcfe903310164c24b70 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 11:37:29 +0000 Subject: [PATCH 04/11] Remote MySQL server --- dancer/app.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dancer/app.pl b/dancer/app.pl index 93fb2817fa9..6e4751bb88e 100755 --- a/dancer/app.pl +++ b/dancer/app.pl @@ -6,7 +6,8 @@ use Dancer::Plugin::Database; set serializer => 'JSON'; -my $dbh = database({ driver => 'mysql', database => 'test' }); +#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!' } From 634f4b41c596235c240d0b55f02338df8725989d Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 12:54:10 +0100 Subject: [PATCH 05/11] Added README file --- dancer/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dancer/README.md diff --git a/dancer/README.md b/dancer/README.md new file mode 100644 index 00000000000..681123c0e34 --- /dev/null +++ b/dancer/README.md @@ -0,0 +1,14 @@ +# 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) From 0c47b695b2feb7b788d1864aa6ca136b2bdb397c Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 12:57:30 +0100 Subject: [PATCH 06/11] Added README file --- mojolicious/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 mojolicious/README.md diff --git a/mojolicious/README.md b/mojolicious/README.md new file mode 100644 index 00000000000..8ea9d7ba62c --- /dev/null +++ b/mojolicious/README.md @@ -0,0 +1,22 @@ +# 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 + +Something along the lines of + + plackup -E production -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl From 01b653bbe28c6bade719d3f63ea97169bfe6cfd1 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 13:00:48 +0100 Subject: [PATCH 07/11] Added deployment notes --- dancer/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dancer/README.md b/dancer/README.md index 681123c0e34..c2afcf7639c 100644 --- a/dancer/README.md +++ b/dancer/README.md @@ -12,3 +12,13 @@ * 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 From 5ad6c001e22a969aa0c1130cf48b30ae7589c678 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 13:02:26 +0100 Subject: [PATCH 08/11] Added deployment notes --- mojolicious/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mojolicious/README.md b/mojolicious/README.md index 8ea9d7ba62c..7b98cee5a85 100644 --- a/mojolicious/README.md +++ b/mojolicious/README.md @@ -20,3 +20,9 @@ with nginx, nginx.conf provided) 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 + +or the equivalent Morbo or Hypnotoad commands. From 8d06781fa4d7fa71ffe500647e928cd1247cf6a6 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 13:03:00 +0100 Subject: [PATCH 09/11] Added nginx.conf --- mojolicious/nginx.conf | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 mojolicious/nginx.conf diff --git a/mojolicious/nginx.conf b/mojolicious/nginx.conf new file mode 100644 index 00000000000..7e228093bf8 --- /dev/null +++ b/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; + } + } +} From 1583350a5988e394d54461e0f9b5e94fc1f390e2 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 13:03:45 +0100 Subject: [PATCH 10/11] Deleted original README --- mojolicious/README.mdown | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 mojolicious/README.mdown diff --git a/mojolicious/README.mdown b/mojolicious/README.mdown deleted file mode 100644 index 10a12e86d9f..00000000000 --- a/mojolicious/README.mdown +++ /dev/null @@ -1,3 +0,0 @@ -Start with - - ./app.pl daemon From c93f4ac81952e486184935a0ac5e5ac1d35b8062 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Sun, 14 Apr 2013 13:49:16 +0100 Subject: [PATCH 11/11] Fixed the production mode setting --- mojolicious/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mojolicious/README.md b/mojolicious/README.md index 7b98cee5a85..78ba5f8fbbb 100644 --- a/mojolicious/README.md +++ b/mojolicious/README.md @@ -17,12 +17,16 @@ with nginx, nginx.conf provided) # Deployment +Set production mode: + + export MOJO_MODE=production + Something along the lines of - plackup -E production -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl + plackup -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 + plackup -s Starman --port 8080 --workers=2 -a ./app.pl or the equivalent Morbo or Hypnotoad commands.