Subscribed unsubscribe Subscribe Subscribe

Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

Kossy-0.24 Trial has been released. It contains new BodyParser

I released Kossy-0.24-Trial. It contains new request-body parser Kossy::BodyParser.

https://metacpan.org/release/KAZEBURO/Kossy-0.24-TRIAL

Kossy::BodyParser is based on tokuhirom's Plack::BodyParser
https://github.com/plack/Plack/pull/434

I think that this trial version of Kossy is positioned as verification of the next Plack.

Benchmark

package MyApp;

use strict;
use warnings;
use Kossy;

get "/" => sub {
    my ( $self, $c )  = @_;
    $c->response->body("ok");
};

router [qw/GET POST/] => "/bench" => sub {
    my ( $self, $c )  = @_;
    my $param = $c->req->param('q');
    $c->response->body("ok => " . $param);
};

package main;

use HTTP::Request::Common;
use HTTP::Message::PSGI;
use Plack::Test;
use Plack::Builder;
use Benchmark qw/cmpthese timethese/;

my $env = req_to_psgi(GET '/');
my $env_get = req_to_psgi(GET '/bench?q=HTTP%3A%3ARequest%3A%3ACommon&ie=UTF-8&sourceid=chrome');
my $env_post = req_to_psgi(POST '/bench',
                           [ q=>'HTTP::Request::Common', ie => 'UTF-8', sourceid => 'chrome' ] );
my $app = MyApp->psgi;

warn $Kossy::VERSION;

cmpthese(timethese(0,{
    'kossy_noparam' => sub {
        $app->($env);
    },
    'kossy_get' => sub {
        $app->($env_get);
    },
    'kossy_post' => sub {
        $app->($env_post);
    },
}));

Results

0.23
Benchmark: running kossy_get, kossy_noparam, kossy_post for at least 3 CPU seconds...
 kossy_get:  4 wallclock secs ( 3.26 usr +  0.00 sys =  3.26 CPU) @ 11825.46/s (n=38551)
kossy_noparam:  3 wallclock secs ( 3.23 usr +  0.00 sys =  3.23 CPU) @ 12707.43/s (n=41045)
kossy_post:  3 wallclock secs ( 3.02 usr +  0.00 sys =  3.02 CPU) @ 11577.81/s (n=34965)
                 Rate    kossy_post     kossy_get kossy_noparam
kossy_post    11578/s            --           -2%           -9%
kossy_get     11825/s            2%            --           -7%
kossy_noparam 12707/s           10%            7%            --
0.24
Benchmark: running kossy_get, kossy_noparam, kossy_post for at least 3 CPU seconds...
 kossy_get:  3 wallclock secs ( 3.21 usr +  0.00 sys =  3.21 CPU) @ 12763.24/s (n=40970)
kossy_noparam:  3 wallclock secs ( 3.11 usr +  0.00 sys =  3.11 CPU) @ 13610.29/s (n=42328)
kossy_post:  3 wallclock secs ( 3.29 usr +  0.00 sys =  3.29 CPU) @ 12449.85/s (n=40960)
                 Rate    kossy_post     kossy_get kossy_noparam
kossy_post    12450/s            --           -2%           -9%
kossy_get     12763/s            3%            --           -6%
kossy_noparam 13610/s            9%            7%            --