Created
February 26, 2012 20:19
-
-
Save sugar84/1918805 to your computer and use it in GitHub Desktop.
some psgi app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.12.3; | |
use FindBin qw($Bin); | |
use lib "$Bin/../lib"; | |
use DB::Connect; | |
use HTML::Template; | |
use Plack::Request; | |
my $dbh = DB::Connect->new(config => "$Bin/../conf/mysql.conf")->connect; | |
my $tpl = HTML::Template->new( | |
'path' => [ "$Bin/../templates" ], | |
'filename' => 'test/base.tpl', | |
'die_on_bad_params' => 0, | |
); | |
my $app = sub { | |
my($env) = @_; | |
my $req = Plack::Request->new($env); | |
my $ext_id = $req->param('ext_id') || 1 + int rand 10; | |
my $med = rand 8000; | |
my $limit = 20; | |
my $data = $dbh->selectall_arrayref("SELECT | |
id ID, data DATA, ext_id EXT_ID | |
FROM test | |
WHERE | |
ext_id = ? AND | |
digit <= ? | |
ORDER BY rand() | |
LIMIT $limit", | |
{Slice => {}}, $ext_id, $med); | |
my $res = $req->new_response( | |
200, | |
[ content_type => 'text/html; charset=utf8' ], | |
); | |
$tpl->param(DATA => $data); | |
my $body = $tpl->output; | |
utf8::encode($body); | |
$res->body( $body ); | |
return $res->finalize(); | |
}; | |
$app; | |
__END__ | |
ab -n3000 -c12 127.0.0.1:5000/ | |
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 | |
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 300 requests | |
Completed 600 requests | |
Completed 900 requests | |
Completed 1200 requests | |
Completed 1500 requests | |
Completed 1800 requests | |
Completed 2100 requests | |
Completed 2400 requests | |
Completed 2700 requests | |
Finished 3000 requests | |
Server Software: | |
Server Hostname: 127.0.0.1 | |
Server Port: 5000 | |
Document Path: / | |
Document Length: 2210 bytes | |
Concurrency Level: 12 | |
Time taken for tests: 6.401 seconds | |
Complete requests: 3000 | |
Failed requests: 2987 | |
(Connect: 0, Length: 2987, Exceptions: 0) | |
Broken pipe errors: 0 | |
Total transferred: 6221340 bytes | |
HTML transferred: 6047340 bytes | |
Requests per second: 468.68 [#/sec] (mean) | |
Time per request: 25.60 [ms] (mean) | |
Time per request: 2.13 [ms] (mean, across all concurrent requests) | |
Transfer rate: 971.93 [Kbytes/sec] received | |
Connnection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.0 0 0 | |
Processing: 9 23 0.8 23 32 | |
Waiting: 9 23 0.8 23 32 | |
Total: 9 23 0.8 23 32 | |
Percentage of the requests served within a certain time (ms) | |
50% 23 | |
66% 23 | |
75% 24 | |
80% 24 | |
90% 24 | |
95% 24 | |
98% 25 | |
99% 25 | |
100% 32 (last request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment