I released Plack::Middleware::Deflater version 0.10.
cpan: https://metacpan.org/release/Plack-Middleware-Deflater
github: https://github.com/miyagawa/Plack-Middleware-Deflater
In version 0.10. I replaced IO::Compress::(Gzip|Deflate) with new encoder implementation PM::Deflater::Encoder.
IO::Compress::(Gzip|Deflate)->new is bit slowly. PM::Deflater::Encoder use Compresss::Zlib directory. Throughput will be better from 10% to 100% by content size.
Here is screenshots of nytprof flame graph
version 0.09
version 0.10
Benchmarks
run Starlet server that delivers a html
carton exec -- plackup -s Starlet --max-workers=15 -E production
-e 'open(my $fh,"sample.html");
local $/;my $body = <$fh>;
enable Deflater;
sub {[200,["Content-Type"=>"text/html"],[$body]]} '
an benchmark with ab command from another host
case#1 168Byte html
## not compress
$ ab -c 15 -n 10000 'http://10.x.x.x:5000/'
Document Length: 168 bytes
Requests per second: 19375.30 [#/sec] (mean)
Time per request: 0.774 [ms] (mean)
## enable gzip PM::Deflater 0.09
$ ab -c 15 -n 10000 -H 'Accept-Encoding: gzip,deflate' 'http://10.x.x.x:5000/'
Document Length: 139 bytes
Requests per second: 8765.65 [#/sec] (mean)
Time per request: 1.711 [ms] (mean)
## enable gzip PM::Deflater 0.10
$ ab -c 15 -n 10000 -H 'Accept-Encoding: gzip,deflate' 'http://10.x.x.x:5000/'
Document Length: 139 bytes
Requests per second: 12656.63 [#/sec] (mean)
Time per request: 1.185 [ms] (mean)
case#2 14KB html
## not compress
$ ab -c 15 -n 10000 'http://10.x.x.x:5000/'
Document Length: 13974 bytes
Requests per second: 7972.88 [#/sec] (mean)
Time per request: 1.881 [ms] (mean)
# ≒ 1Gbps
## enable gzip PM::Deflater 0.09
$ ab -c 15 -n 10000 -H 'Accept-Encoding: gzip,deflate' 'http://10.x.x.x:5000/'
Document Length: 4350 bytes
Requests per second: 5851.74 [#/sec] (mean)
Time per request: 2.563 [ms] (mean)
## enable gzip PM::Deflater 0.10
$ ab -c 15 -n 10000 -H 'Accept-Encoding: gzip,deflate' 'http://10.x.x.x:5000/'
Document Length: 4350 bytes
Requests per second: 7580.95 [#/sec] (mean)
Time per request: 1.979 [ms] (mean)
—
Plack::Middleware::Deflaterの0.10をリリースしました。IO::Compress::(Gzip|Deflate)が遅いなと思うところがあったので、 Compresss::Zlibを直接使って圧縮を行うEncoderを実装し直しました。コンテンツサイズによって10%〜100%ぐらい速くなります