Skip to content

Commit b56ccf4

Browse files
author
Pedro Figueiredo
committed
Merge pull request #2 from pfig/feature/mojolicious
Mojolicious (Perl) app
2 parents e4d46b7 + 8038d2d commit b56ccf4

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

mojolicious/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Setup
2+
3+
* Perl 5.16.3
4+
* MySQL 5.5
5+
* Wrk 2.0
6+
7+
# Requirements
8+
9+
* Mojolicious
10+
* Mojolicious::Plugin::Database
11+
* DBD::mysql
12+
* Starman (if using Starman as web server)
13+
* Plack (for plackup)
14+
* nginx (if you want to front Mojolicious
15+
with nginx, nginx.conf provided)
16+
* Morbo and Hypnotoad provided by Mojolicious
17+
18+
# Deployment
19+
20+
Set production mode:
21+
22+
export MOJO_MODE=production
23+
24+
Something along the lines of
25+
26+
plackup -s Starman --workers=2 -l /tmp/frameworks-benchmark.sock -a ./app.pl
27+
28+
if you want to front it with nginx, otherwise
29+
30+
plackup -s Starman --port 8080 --workers=2 -a ./app.pl
31+
32+
or the equivalent Morbo or Hypnotoad commands.

mojolicious/app.pl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env perl
2+
use Mojolicious::Lite;
3+
use Mojolicious::Plugin::Database;
4+
5+
plugin 'database', {
6+
dsn => 'dbi:mysql:dbname=test',
7+
username => 'root',
8+
password => ''
9+
};
10+
11+
get '/json' => sub {
12+
my $self = shift;
13+
$self->render( json => { message => 'Hello, world!' } );
14+
};
15+
16+
get '/db' => sub {
17+
my $self = shift;
18+
my $queries = $self->param('queries') || 1;
19+
my @response;
20+
my $sth = $self->db->prepare( 'SELECT randomnumber FROM world WHERE id = ?' );
21+
for ( 1 .. $queries ) {
22+
my $id = int rand 10000 + 1;
23+
my $res = $sth->execute( $id );
24+
if ( my $row = $sth->fetchrow_arrayref ) {
25+
push @response, { id => $id, randomNumber => $row->[0] };
26+
}
27+
}
28+
$self->render( json => \@response );
29+
};
30+
31+
app->start;

mojolicious/nginx.conf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
user www;
2+
3+
worker_processes 2;
4+
5+
events {
6+
worker_connections 1024;
7+
}
8+
9+
http {
10+
output_buffers 1 32k;
11+
postpone_output 1460;
12+
13+
sendfile on;
14+
tcp_nopush on;
15+
16+
tcp_nodelay on;
17+
18+
upstream backendurl {
19+
server unix:/tmp/frameworks-benchmark.sock;
20+
}
21+
22+
server {
23+
listen 8888;
24+
server_name localhost;
25+
26+
location / {
27+
try_files $uri @proxy;
28+
access_log off;
29+
expires max;
30+
}
31+
32+
location @proxy {
33+
proxy_set_header Host $http_host;
34+
proxy_pass http://backendurl;
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)