Browse Source

Merge pull request #676 from tudorconstantin/master

performance improvements for mojolicious
Mike Smith 11 years ago
parent
commit
da25374b94
3 changed files with 10 additions and 6 deletions
  1. 4 3
      mojolicious/README.md
  2. 5 2
      mojolicious/app.pl
  3. 1 1
      mojolicious/nginx.conf

+ 4 - 3
mojolicious/README.md

@@ -7,7 +7,8 @@
 # Requirements
 # Requirements
 
 
 * Mojolicious
 * Mojolicious
-* Mojolicious::Plugin::Database
+* JSON::XS
+* DBI
 * DBD::mysql
 * DBD::mysql
 * Starman (if using Starman as web server)
 * Starman (if using Starman as web server)
 * Plack (for plackup)
 * Plack (for plackup)
@@ -23,10 +24,10 @@ Set production mode:
 
 
 Something along the lines of
 Something along the lines of
 
 
-    plackup -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl
+    plackup -s Starman --workers=8 -l /tmp/frameworks-benchmark.sock -a ./app.pl
 
 
 if you want to front it with nginx, otherwise
 if you want to front it with nginx, otherwise
 
 
-    plackup -s Starman --port 8080 --workers=2 -a ./app.pl
+    plackup -s Starman --port 8080 --workers=8 -a ./app.pl
 
 
 or the equivalent Morbo or Hypnotoad commands.
 or the equivalent Morbo or Hypnotoad commands.

+ 5 - 2
mojolicious/app.pl

@@ -1,14 +1,17 @@
 #!/usr/bin/env perl
 #!/usr/bin/env perl
 use Mojolicious::Lite;
 use Mojolicious::Lite;
+use JSON::XS;
+use Memoize;
 use DBI;
 use DBI;
 
 
 my $dsn = "dbi:mysql:database=hello_world;host=localhost;port=3306";
 my $dsn = "dbi:mysql:database=hello_world;host=localhost;port=3306";
 my $dbh = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
 my $dbh = DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
 my $sth = $dbh->prepare("SELECT * FROM World where id = ?");
 my $sth = $dbh->prepare("SELECT * FROM World where id = ?");
 
 
+
 get '/json' => sub {
 get '/json' => sub {
-    my $self = shift;
-    $self->render( json => { message => 'Hello, world!' } );
+    my $self = shift;    
+    $self->render( text => JSON::XS::encode_json( { message => 'Hello, world!' } ), format => 'json' );
 };
 };
 
 
 get '/db' => sub {
 get '/db' => sub {

+ 1 - 1
mojolicious/nginx.conf

@@ -1,7 +1,7 @@
 user tfb;
 user tfb;
 error_log stderr error;
 error_log stderr error;
 
 
-worker_processes 2;
+worker_processes 8;
 
 
 events {
 events {
   worker_connections  1024;
   worker_connections  1024;