Tatsuhiko Miyagawa's Blog

Plack standalone and Apache2 support

September 14, 2009

The YAPC::Asia hackathon is over but hacking is continuing …

  • Kazuho made the fast XS based HTTP header parser HTTP::Parser::XS and I wrote Plack::HTTPParser::PP which is a pure perl fallback and has the same API. XS version is 10 times faster (but makes the whole server only about 20% faster because header parsing takes smaller part of the processing time compared to other I/O stuff)
  • Kazuho also patched Leont’s Sys::Sendfile to support Mac OS X.
  • WIth those two in my toolkit, I created Plack::Impl::Standalone which is a pretty simple IO::Socket::INET based standalone, single thread and non-forking server that uses the XS parser and sendfile(2) if available (and fallback to pure perl).
  • I also made the first pass of the Apache2 backend.

And now it’s time to benchmark: overall, the standalone daemon beats everything else even though it’s a single thread, non-forking daemon: the simple Hello World is like 2500 req/s on Standalone and 2000 req/s with Apache2, 1200 req/s with ServerSimple. Also the Catalyst’s default Welcome page runs 200 req/s with Standalone and 140 req/s with Apache2. The numbers don’t really change if I increased the concurrency (-c) to a bigger number like 20. 

Note that to run Catalyst via PSGI on Apache2 on Leopard I needed to re-install CPAN modules with 64bit, otherwise I could run Apache in 32bit mode (as a PPC binary) but that makes the whole Apache really slow.

In other news, the Catalyst::Engine::PSGI and Plack::Impl::Standalone now passes all live and aggregated tests from Catalyst-Runtime distribution. In the process I’ve found a pile of bugs in both Engine::PSGI and Impl::Standalone and they’re all fixed. This is a huge milestone! 

The other implementations like ServerSimple also get very close to pass 100% and it also has revealed some weird bugs or corner cases around URI decoding etc. Fun.