PHP https://janezurevc.name/ en HHVM and Drupal (i.e. Drupal drinks some RedBull) https://janezurevc.name/hhvm-and-drupal-ie-drupal-drinks-some-redbull <span>HHVM and Drupal (i.e. Drupal drinks some RedBull)</span> <span><span lang="" about="https://janezurevc.name/users/slashrsm" typeof="schema:Person" property="schema:name" datatype="" xml:lang="">slashrsm</span></span> <span>Mon, 30.12.2013 - 12:27</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>I've been following <a href="https://en.wikipedia.org/wiki/HipHop_for_PHP">HHVM (HipHop Virtual machine)</a> for some time now. Project got a bit more of my attention about a year ago, after session at <a href="https://en.wikipedia.org/wiki/FOSDEM">FOSDEM</a> 2013 by <a href="https://github.com/sgolemon">Sara Golemon</a>. PHP has been criticized for quite a lot of it's characteristics, performance definitely being one of those. HHVM seemed to be very promising about fixing it and that's why it got my attention in the first place. Immediately after last year's FOSDEM I tried it with <a href="https://drupal.org">Drupal</a>, but my attempt unfortunately failed miserably. HHVM was simply not yet ready for that. </p> <p><img src="https://janezurevc.name/sites/default/files/heart.jpg" data-entity-type="file" data-entity-uuid="b34091d4-6d63-49f3-8d00-f2046080139a" /></p> <h2>But first a bit of history...</h2> <p>HipHop was initially developed by Facebook (and they are still it's main contributor). Facebook was looking for something that would make their PHP code base perform faster while still retaining benefits that PHP brings (primarily ease of use for developers). Initially they created a compiler (HPHPc) that transformed a PHP script into a C++ program, which was then compiled into a binary. This approach showed dramatic increase in performance, but also had some problems. HPHPc did not fully support PHP language and was not a simple drop-in replacement for "standard" (Zend) PHP.</p> <p>Facebook decided to deprecate HPHPc, start working on a bit different approach and HHVM was born. HHVM is a <a href="https://en.wikipedia.org/wiki/Just-in-time_compilation">Just-in-time compiler (JIT)</a> for PHP. It behaves very similar to standard interpreter when observed from the outside (which means it can be a drop-in replacement for it), but it works quite different internally. It will run a program as an interpreter at the beginning of execution, collect some statistics for optimization and eventually compile it to byte code on the fly. Compiled program will then run much faster than it's interpreted version. It is quite obvious that we get true performance gains with applications that run for a longer period of time (because of initial interpretation phase and on-the-fly compilation). A standard web (Drupal) application, which is deployed to production servers from time to time, is exactly what we're looking for.</p> <h2>Where are we now?</h2> <p>HHVM achieved same level of performance as HPHPc about a year ago and it is currently supporting almost entire PHP 5.4 language. Facebook recently stated that supporting main PHP frameworks/projects became one of their top priorities with HHVM and they started to run unit tests of ~20 projects to get an idea about the level of support. Drupal is one of those projects and there are currently <a href="https://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16">100% of it's unit tests</a> (not functional AFAIK) passing when running on HHVM. That fact encouraged me to test HHVM and Drupal once again and this time it went much better than a year ago. </p> <p>I was able to run Drupal, navigate through it structure, add a node, edit it, display it ... To make it short, it looks very promising. I found some problems with files, but initial poking made me think that we're dealing with solvable problems there.</p> <h2>How does it perform?</h2> <p>I was also interested in performance part (no shi** :). I executed 1000 anonymous requests against Drupal's front page (page cache disabled) using this command:</p> <pre> ab -c 50 -n 1000 https://localhost/\?q\=node </pre><p>I used PHP 5.5.3 (version that ships with Ubuntu 13.10) with zendoptimizer opcode cache enabled and HHVM which I compiled from master (<a href="https://github.com/facebook/hhvm/commit/1b389496b4dcb240fffe9a22e9121d4e82348c7f">1b389496b4dcb240fffe9a22e9121d4e82348c7f</a> more precisely). I repeated same test three times; PHP 5.5.3, HHVM (cold start) and HHVM (after initial warm-up).</p> <h3>PHP 5.5.3</h3> <pre> Requests per second: 103.00 [#/sec] (mean) Time per request: 485.420 [ms] (mean) Time per request: 9.708 [ms] (mean, across all concurrent requests) Transfer rate: 1160.00 [Kbytes/sec] received </pre><h3>HHVM (cold-start)</h3> <pre> Requests per second: 183.08 [#/sec] (mean) Time per request: 273.101 [ms] (mean) Time per request: 5.462 [ms] (mean, across all concurrent requests) Transfer rate: 2008.37 [Kbytes/sec] received </pre><h3>HHVM (warmed-up)</h3> <pre> Requests per second: 308.31 [#/sec] (mean) Time per request: 162.173 [ms] (mean) Time per request: 3.243 [ms] (mean, across all concurrent requests) Transfer rate: 3382.10 [Kbytes/sec] received </pre><p>Results are mind-blowing. HHVM is faster than PHP even in it's interpreter phase (which is actually very surprising) and around three times faster after initial warm-up. This improvement is so significant that it would probably result in savings of tens (if not hundreds) of thousands of Euros/dollars in case of a high-traffic enterprise site. Not that Drupal runs any of that sort....</p> <h2>Where do we go next?</h2> <p>HHVM got quite some attention after their posts lately. It was reported that <a href="https://en.wikipedia.org/wiki/Rasmus_Lerdorf">Rasmus Lerdorf</a> (the founder of PHP) <a href="https://www.infoworld.com/t/php-web/believe-the-hype-php-founder-backs-facebooks-hiphop-technology-231012">publicly supported</a> Facebook's efforts. There were also some other well-known members of PHP community that <a href="https://pooteeweet.org/blog/2259">discussed HHVM</a> and some <a href="https://www.doctrine-project.org/blog/our-hhvm-roadmap.html">projects already started with their efforts</a> to officially support HHVM in the future.</p> <p>How about Drupal? Do we want to be on this wave and start thinking more seriously about this? Who knows how much progress will HHVM achieve by the time Drupal 8 achieves <a href="https://buytaert.net/the-gartner-hype-cycle-and-drupal">plateau of productivity</a>. Do we want to make sure that D8 runs on HHVM by default? Do we want to check how much effort would take to make D7 run on it? Drupal likes to present itself as a solution for high-end projects and I think that we should at least start discussing this question. High-end projects would benefit the most out of Drupal and HHVM loving each other and that makes me think that there should be some level of interest for pushing this forward.</p> <h2>Want to know more?</h2> <p><a href="https://www.hhvm.com">HHVM team writes a blog</a> where they post news about it. It's <a href="https://github.com/facebook/hhvm/">code is hosted on GitHub</a>, where you'll also find <a href="https://github.com/facebook/hhvm/wiki">more information</a> if you want to build, install or contribute to HHVM. There are also <a href="https://github.com/facebook/hhvm/wiki#installing-pre-built-packages-for-hhvm">pre-built packages</a> available for most popular GNU/Linux distributions.</p> </div> Mon, 30 Dec 2013 11:27:19 +0000 slashrsm 70 at https://janezurevc.name