Hateburo: kazeburo hatenablog

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

Monoceros-0.26 and Plack::Middleware::Static::OpenFileCache

Monoceros-0.26 uses sendfile(2) for sending file if Sys::Sendfile is available.

https://metacpan.org/release/Monoceros

Plack::Middleware::Static::OpenFileCache can cache opened file handles like nginx's open_file_cache. Static::OpenFileCache also caches the whole of files if content size is less than buf_size.

https://metacpan.org/release/Plack-Middleware-Static-OpenFileCache

# synopsis

use Plack::Builder;
builder {
    enable Static::OpenFileCache,
        path=>sub{s{^/static/}{}},
        root=>"/path/to";
    $app
}

benchmark

benchmark on Macbook Air.

benchmark client
$ ab -c 1 -n 5000  http://127.0.0.1:5000/static/jquery-1.10.2.min.js

jquery-1.10.2.min.js has 93KB length.

server
$ plackup -E production -s Monoceros --workers 1 --max-reqs-per-child 50000 \
  -e 'enable Static::OpenFileCache, path=>sub{s{^/static/}{}},root=>"./";sub{}'
benchmark results

f:id:kazeburo:20131028135020p:plain

Of course, I recommends to use reverse-proxy for serving static-files in the production.