You’re measuring oddly or the wrong part, maybe? It will never take less than 3 seconds to connect to the mock DB server, because that’s just what the code calls for. The connection to the webapp and its responses are not related though—the $app sub is initialized, holding a DB handle, ready to execute—and seems to be perfectly zippy unless I’m missing something–
moo@cow[21]~>plackup pm-1191821
HTTP::Server::PSGI: Accepting connections at http://0:5000/
--
moo@cow[701]~>time curl http://0:5000/
connect took 3.1313986862815 seconds
0.004u 0.004s 0:00.00 0.0% 0+0k 0+0io 0pf+0w
Here it the same with some internal timing code–
use Time::HiRes qw( sleep gettimeofday tv_interval );
# ...
sub main {
state $db_handle = mock_connect(+shift);
sub {
my $t0 = [ gettimeofday ];
[ 200, [],
[ sprintf "Application sub took %.6f seconds\n",
tv_interval( $t0, [ gettimeofday ] ) ] ];
};
}
# ...
__END__
moo@cow[56]~>curl http://0:5000/
Application sub took 0.000001 seconds
moo@cow[57]~>curl http://0:5000/
Application sub took 0.000002 seconds