Browse Source

merge naturalist-master

Patrick Falls 12 years ago
parent
commit
e7e0b0ca85
11 changed files with 44 additions and 52 deletions
  1. 11 7
      dancer/app.pl
  2. 1 2
      dancer/benchmark_config
  3. 1 1
      dancer/setup.py
  4. 7 14
      installer.py
  5. 9 12
      kelp/app.pl
  6. 1 2
      kelp/benchmark_config
  7. 3 0
      kelp/conf/config.pl
  8. 1 1
      kelp/setup.py
  9. 8 10
      mojolicious/app.pl
  10. 1 2
      mojolicious/benchmark_config
  11. 1 1
      mojolicious/setup.py

+ 11 - 7
dancer/app.pl

@@ -3,11 +3,13 @@ use strict;
 use warnings;
 
 use Dancer ':syntax';
-use Dancer::Plugin::Database;
+use DBI;
+
 set serializer => 'JSON';
 
-#my $dbh = database({ driver => 'mysql', database => 'test' });
-my $dbh = database({ driver => 'mysql', host => 'localhost', database => 'hello_world', username => 'benchmarkdbuser', password => 'benchmarkdbpass' });
+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 = ?");
 
 get '/json' => sub {
     { message => 'Hello, World!' }
@@ -16,13 +18,15 @@ get '/json' => sub {
 get '/db' => sub {
     my $queries = params->{queries} || 1;
     my @response;
-    for( 1 .. $queries ) {
+    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} };
+        $sth->execute($id);
+        if ( my $row = $sth->fetchrow_hashref ) {
+            push @response,
+              { id => $id, randomNumber => $row->{randomNumber} };
         }
     }
-    { \@response }
+    return \@response;
 };
 
 Dancer->dance;

+ 1 - 2
dancer/benchmark_config

@@ -15,5 +15,4 @@
       "sort": 77
     }
   }]
-}
-
+}

+ 1 - 1
dancer/setup.py

@@ -24,7 +24,7 @@ def stop():
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     out, err = p.communicate()
     for line in out.splitlines():
-      if 'plackup' in line:
+      if 'starman' in line:
         pid = int(line.split(None, 2)[1])
         os.kill(pid, 9)
     return 0

+ 7 - 14
installer.py

@@ -89,6 +89,13 @@ class Installer:
 
     self.__run_command("curl http://go.googlecode.com/files/go1.1beta2.linux-amd64.tar.gz | tar xvz")
 
+    #
+    # Perl
+    #
+
+    self.__run_command("curl -L http://cpanmin.us | perl - --sudo App::cpanminus")
+    self.__run_command("cpanm -S DBI DBD::mysql Kelp Dancer Mojolicious Kelp::Module::JSON::XS Dancer::Plugin::Database Starman Plack JSON")
+
     #
     # php
     #
@@ -128,20 +135,6 @@ class Installer:
     self.__run_command("sudo ringo-admin install oberhamsi/reinhardt")
     self.__run_command("sudo ringo-admin install grob/ringo-sqlstore")
 
-    #
-    # Perl
-    #
-    self.__run_command("sudo cpan install Plack", send_yes=True)
-    self.__run_command("sudo cpan install Starman")
-    self.__run_command("sudo cpan install DBD::mysql")
-    self.__run_command("sudo cpan install DBI")
-    self.__run_command("sudo cpan install Dancer")
-    self.__run_command("sudo cpan install Dancer::Plugin::Database")
-    self.__run_command("sudo cpan install JSON", send_yes=True)
-    self.__run_command("sudo cpan install Kelp", send_yes=True)
-    self.__run_command("sudo cpan install Mojolicious", send_yes=True)
-    self.__run_command("sudo cpan install Mojolicious:Plugin:Database", send_yes=True)
-
     #######################################
     # Webservers
     #######################################

+ 9 - 12
kelp/app.pl

@@ -2,12 +2,9 @@
 use Kelp::Less;
 use DBI;
 
-attr dbh => sub {
-    my $database = 'hello_world';
-    my $host     = 'localhost';
-    my $dsn      = 'dbi:mysql:database=hello_world;host=localhost;port=3306';
-    DBI->connect( $dsn, 'benchmarkdbuser', 'benchmarkdbpass', {} );
-};
+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 = ?");
 
 get '/json' => sub {
     { message => 'Hello, World!' }
@@ -15,17 +12,17 @@ get '/json' => sub {
 
 get '/db' => sub {
     my $self = shift;
-    my $queries = param('queries') || 1;
+    my $queries = $self->param('queries') || 1;
     my @response;
-    my $sth = $self->dbh->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] };
+        $sth->execute($id);
+        if ( my $row = $sth->fetchrow_hashref ) {
+            push @response,
+              { id => $id, randomNumber => $row->{randomNumber} };
         }
     }
-    { \@response }
+    return \@response;
 };
 
 run;

+ 1 - 2
kelp/benchmark_config

@@ -15,5 +15,4 @@
       "sort": 79
     }
   }]
-}
-
+}

+ 3 - 0
kelp/conf/config.pl

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

+ 1 - 1
kelp/setup.py

@@ -24,7 +24,7 @@ def stop():
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     out, err = p.communicate()
     for line in out.splitlines():
-      if 'plackup' in line:
+      if 'starman' in line:
         pid = int(line.split(None, 2)[1])
         os.kill(pid, 9)
     return 0

+ 8 - 10
mojolicious/app.pl

@@ -1,12 +1,10 @@
 #!/usr/bin/env perl
 use Mojolicious::Lite;
-use Mojolicious::Plugin::Database;
+use DBI;
 
-plugin 'database', {
-    dsn      => 'dbi:mysql:dbname=hello_world;host=localhost',
-    username => 'benchmarkdbuser',
-    password => 'benchmarkdbpass'
-};
+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 = ?");
 
 get '/json' => sub {
     my $self = shift;
@@ -17,12 +15,12 @@ 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] };
+        $sth->execute($id);
+        if ( my $row = $sth->fetchrow_hashref ) {
+            push @response,
+              { id => $id, randomNumber => $row->{randomNumber} };
         }
     }
     $self->render( json => \@response );

+ 1 - 2
mojolicious/benchmark_config

@@ -15,5 +15,4 @@
       "sort": 81
     }
   }]
-}
-
+}

+ 1 - 1
mojolicious/setup.py

@@ -24,7 +24,7 @@ def stop():
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     out, err = p.communicate()
     for line in out.splitlines():
-      if 'plackup' in line:
+      if 'starman' in line:
         pid = int(line.split(None, 2)[1])
         os.kill(pid, 9)
     return 0