HHVM with Symfony 2 looks amazing

  • Christian Stocker

With the recent announcement of Facebook that their HHVM is now more and more compatible with most of the popular framework, I was intrigued to finally try it out. We're currently building a Symfony2 based application, which has pretty high performance requirements (but we can mostly achieve them with varnish), so I went and did some performance tests on that real-life app.

The application basically gets data from an ElasticSearch server and then transforms them to JSON. Nothing too fancy from the output perspective, but we use many features of Symfony2 and what was clear from the beginning is that the more data it gets from ElasticSearch the slower the requests get. Meaning that we loose a lot of time in the serialization part (we use JMSSerializer for that).

In short, the numbers were amazing. I also compared PHP 5.3 with APC against 5.5 with opcache, that alone gave some pretty decent improvements.

The setup I did the tests on was a QuadCore Intel i7-4770 CPU @ 3.40GHz server over at Hetzner with SSD disks and more than enough RAM. The actual application ran in a VirtualBox container with 4 CPUs and 2 GB of RAM. I used Apache Bench for the tests with the HHVM vagrant VM running Ubuntu 12.04, but I installed the pre-built HHVM from their repo in the end.

I made 3 different requests with different amount of data the script had to get from ElasticSearch. One was approx. 7kb in response, the other 80kb and the last 220kb. I didn't it with different concurrency settings (1-50) and ran Apache Bench with 500 requests per run. The figures below are averages over those 500 requests.

I didn't do performance measurements for PHP 5.3 with more than 6 concurrent requests, because I added 10,20,50 later and didn't repeat for 5.3, but the trend is clear nevertheless.

As you can see below, in general the longer the PHP request ran, the more we gained from HHVM, up to and sometimes more than 300% against PHP 5.3, and about 200% against PHP 5.5. Only switching from PHP 5.3 to PHP 5.5 can save you up to twice the time, as well. So it is very much worth upgrading to 5.5. I find both numbers pretty amazing.

If you really need every millisecond performance, considering HHVM is worth some investigation. These numbers are very promising. And I don't had to change one line of code in our application. As we don't use it yet in production, I can't say anything about stability. Obviously tools like New Relic are, at least for now, also out of the question with HHVM.

Requests per second, small response

The higher the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
1528481157 %96 %163 %
2120163207173 %127 %136 %
3154219285185 %130 %142 %
4172247317185 %129 %144 %
5186256342184 %134 %138 %
6203259340168 %132 %128 %
10253443175 %
20247441179 %
50258380147 %

Requests per second, middle response

The higher the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
1101426269 %184 %146 %
2192956295 %193 %153 %
3284279286 %186 %154 %
4345192271 %179 %151 %
5355398279 %186 %150 %
63550101285 %203 %140 %
1056113202 %
2053105197 %
5056108193 %
image

Requests per second, large response

The higher the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
14612283 %179 %158 %
281225333 %207 %161 %
3111837324 %208 %155 %
4152246307 %207 %148 %
5152348318 %208 %153 %
6152451339 %215 %158 %
102451218 %
202449208 %
502450212 %
image

Median response time in ms, short response

The lower the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
11511960 %82 %73 %
216121059 %79 %75 %
319131155 %81 %68 %
423161354 %78 %70 %
526181454 %78 %69 %
629221757 %75 %76 %
10382155 %
20784355 %
5019110555 %
image

Median response time in ms, middle response

The lower the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
198613233 %53 %62 %
2103663433 %52 %64 %
3107663634 %55 %62 %
4112714036 %56 %63 %
5138894936 %55 %64 %
61711125733 %51 %65 %
101748348 %
2036618551 %
5087245152 %
image

Median response time in ms, large response

The lower the better

ConcurrencyPHP 5.3PHP 5.5HHVMHHVM vs 5.3HHVM vs 5.55.5 vs 5.3
12361497130 %48 %63 %
22491587530 %47 %63 %
32531617730 %48 %64 %
42611688131 %48 %64 %
53272119830 %46 %65 %
639424611529 %47 %62 %
1041918945 %
2084339447 %
50206996847 %
image

I will have a look at memory consumption in a follow up post.


Tell us what you think