Alternative PHP Runtimes Attila-Mihaly Balazs
it-events.ro javaadvent.com
Agenda ● Short introduction / methodology ● The standard interpreter ○ opcode caches ● Facebook's HHVM ● Caucho Resin ● IIS + PHP ● IIS + Phalanger ● Other projects ● Benchmark results ● Conclusions
Methodology ● ● ● ●
Quad-core i7 VM + 1G RAM Ubuntu 12.10 (12.04), Windows 7 Pro time php bench.php Mirror of transylvania-jug.org (Wordpress 3.4.2) + MariaDB / MySQL ○ ab -n100 -c2 / ○ pre-warm for JITed systems
What I might have done wrong: ● VMs are unreliable for timing ● inadequate hardware? different OSs? ● Apache? prefork? fastcgi? nginx? lighthttpd? ● non-realistic traffic patterns ● database (connection, query parsing, etc) may dominate ... treat this as one-more datapoint
The standard PHP interpreter Highlights ● Easy to use ● Available on a wide variety of platforms ● Compatibility Two-step execution process: ● parsing + include resolution > opcodes ● opcode interpretation Done on every request (!) Obvious optimization: cache the result of the first step and reuse it as long as the files don't change. Extensions implementing this: ● APC ● XCache ● eAcceleartor ● ZendServer ● WinCache*
Facebook's HHVM Highlights ● readily packaged ● supported platforms: *nix ● free ● only supports a subset of PHP / extensions Multiple phases of development since early 2010: ● HPHPc > PHP to C++ compiler, uses GCC for binary generation ● HPHPi ● HHVM - uses JIT
Caucho Resin Highlights: ● cross platform (pure Java) ● free (with for-pay version available) ● advanced features provided by container (like DB connection pooling) ● only a (large) subset of extensions reimplemented ● tight integration with Java ● you should know about .war's, WEB-INF, etc
IIS 7.5 Highlights: ● Show me the money! ● Don't use IIS Express or WebPI for production ● More complicated / less documented setup ● Access to Windows-specific features (COM, .NET, AD) ● Should have similar performance to *nix > if not, investigate (DNS lookup issues) Phalanger ● PHP in .NET ● OSS ● Can use native extensions! (but most are reimplemented in .NET) ● you should know about web.config, GACs, etc
Other projects ● ● ● ● ● ● ● ● ●
TalariaTech php-llvm phpc HippyVM PHP.js Roadsend and Roadsend-Raven Pipp PHP4Mono Project Zero / sMash
Benchmark results Platform
bench.php execution time (seconds)
ApacheBench execution time (seconds)
PHP 5.4.6
2.3
15
PHP 5.4.6 with APC 3.1.13
2.3
7.0
PHP 5.4.6 with XCache 2.0.0
2.3
9.0
PHP 5.4.6 with eAccelerator (dev-04-2012)
2.3
6.5
Zender Server CE 5.6.0
3.3
6.9
Hip-Hop VM 1.201212
3.2
8.0
Caucho Resin 4.0.32 GPL
5.4
9.2
IIS 7.5 with PHP 5.4.9 / WinCache 1.3.4
2.4
8.0
IIS 7.5 with Phalanger 3.0
2.5
9.4
Conclusions ● No silver bullet ● Minimal setup: PHP + opcode cache (APC / eAccelerator) ● Use the alternatives for reasons different than speed (for ex. integration) ● Speedup with WordPress caching plugin: >80x (0.08 seconds vs. 6.5 seconds)
it-events.ro