|
@@ -3,9 +3,9 @@ use Web::Simple;
|
|
use JSON::XS;
|
|
use JSON::XS;
|
|
use DBI;
|
|
use DBI;
|
|
|
|
|
|
-my $dsn = "dbi:mysql:database=hello_world;host=localhost;port=3306";
|
|
|
|
|
|
+my $dsn = "dbi:mysql:database=hello_world;host=localhost";
|
|
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 = ?');
|
|
|
|
|
|
sub dispatch_request {
|
|
sub dispatch_request {
|
|
sub (/json) {
|
|
sub (/json) {
|
|
@@ -15,12 +15,13 @@ sub dispatch_request {
|
|
sub (/db + ?queries~) {
|
|
sub (/db + ?queries~) {
|
|
my ($self, $queries) = @_;
|
|
my ($self, $queries) = @_;
|
|
my @response;
|
|
my @response;
|
|
- for ( 1 .. $queries ) {
|
|
|
|
|
|
+ for ( 1 .. $queries || 1 ) {
|
|
my $id = int rand 10000 + 1;
|
|
my $id = int rand 10000 + 1;
|
|
$sth->execute($id);
|
|
$sth->execute($id);
|
|
- if ( my $row = $sth->fetchrow_hashref ) {
|
|
|
|
- push @response, { id => $id, randomNumber => $row->{randomNumber} };
|
|
|
|
|
|
+ if ( my @row = $sth->fetchrow_array ) {
|
|
|
|
+ push @response, { id => $id, randomNumber => $row[1] };
|
|
}
|
|
}
|
|
|
|
+ $sth->finish();
|
|
}
|
|
}
|
|
[ 200, [ 'Content-type' => 'application/json; charset=utf-8', ],
|
|
[ 200, [ 'Content-type' => 'application/json; charset=utf-8', ],
|
|
[ encode_json(\@response)] ];
|
|
[ encode_json(\@response)] ];
|