HHVM: performance testing and compatibility with Joomla, Bitrix and Wordpress

    About HHVM already wrote on Habré. In short: HHVM is a virtual machine from Facebook, which, thanks to translation and JIT compilation of code, allows you to speed up PHP several times. The developers also promise almost complete compatibility with PHP 5.4.

    I decided to compare HHVM with the native interpreter on several tests, and also try to run CMS on it.



    Test conditions


    Testing was carried out in a virtual machine with a configuration of a processor 2 core Core i5 @ 3.3 GHz, 8 GB of RAM.
    OS: Ubuntu 12.04 x86_64.
    PHP: 5.3.10-1ubuntu3.7
    Nginx: 1.1.19
    Apache: 2.2.22
    HHVM: 2.1.0-dev
    In the settings, execution timeouts and memory_limit have been increased, APC has been enabled. No additional tuning was performed.

    HHVM is installed from source according to the instructions .

    Benchmarks


    Several scripts were prepared, each of which was run 50 times: 10 times in PHP CLI, HHVM CLI, Apache + mod_php, nginx + php-fpm, and nginx + HHVM. The average execution time in seconds is presented in the table. The last two columns indicate the gain in speed when using HHVM.

     CLIHTTPSpeed ​​increase compared
    TestPhpHhvmApache + mod_phpNginx + php_fpmNginx + hhvmPHP CLIPHP-FPM
    asort42,417.9N / A 140.918.9137.0%116.7%
    bcmath_factorial3.43.03.43.42,813.9%21.5%
    curl_multi8.68.49.79.09.72.3%-7.0%
    domdocument50,251.054.350.150.1-1.5%0,0%
    for60.536.960.861.0211.263.7%-71.1%
    geoip14,415.614.714.95,0-7.8%198.0%
    getid346.526.946.245.68.572.4%435.5%
    mb_strings22.816.87.022.217.035.8%31.0%
    md536.835.737.037,227,23.2%36.7%
    preg11.610.911.611.710.96.1%7.9%
    prime4.25,64.24.32,5-24.1%71.8%
    sort46.317.8N / A 144.117.5160.1%151.8%
    sqlite12,410.012.612,215,223.7%-19.9%
    strings38.637.537.838,236.03.0%6.3%
    tcp_client15.413,215,517.313.616.9%27.7%
    tcpdf3.32,43.44.41.438.7%215.1%
    thumbnail100.894.893.799.994.26.3%6.1%


    1 - Apache could not execute asort.php and sort.php - fell from out of memory

    asort - sort an associative array of strings with 10 million elements
    bcmath_factorial - calculate the factorial of the number 1000 using the
    bcmul curl_multi function - download 100 files of 1 MB each in 10 streams from Internet
    domdocument - parsing large XML (122 thousand tags) - for example, took sitemap ag.ru
    for - 3 nested for 1000 iterations (total 1 billion)
    geoip - 100 thousand IP searches based on GeoIP
    getid3 - getting ID3 tags from MP3 using getID3 () library - 10 thousand times
    mb_strings- use mb_strlen, mb_ereg_replace, mb_substr, mb_strpos, mb_strtolower 1000 times on the first volume of War and Peace
    md5 - generate md5 from numbers from 1 to 100 million
    preg - search for preg_match_all hex codes for colors, tags and URLs on an HTML page - 1000 time (for example, the main Habr is taken)
    prime - getting all primes from 2 to 1 million by brute force
    sort - sorting an array of strings of 10 million elements with
    sqlite numeric indices - 10 thousand SELECT queries to sqlite3
    strings database - using strlen, str_replace, substr, strpos, strtolower 10 thousand times on the first volume of War and Peace
    tcp_client - 10 thousand connections to localhost and reading 2 MB over TCP ( CHARGEN)
    tcpdf - generation by multi-page PDF library TCPDF - 10 times (example_061.php taken)
    thumbnail - 10 thousand creations thumbnail images using GD imagecopyresized ()

    I also wanted to run the test with Smarty , but HHVM could not execute it.

    Interpretation of Results


    Of course, benchmarks cannot fully show the performance situation. But still, some conclusions can be drawn.

    1. The execution time of each test run did not differ much from the average - so the result can be considered stable.
    2. There are two abnormal results: running the mb_string test on Apache + mod_php too fast and performing for on nginx + HHVM too slow. I rechecked the tests, but I don’t know what is the matter.
    3. What is in the CLI version, what when used for web HHVM gives an advantage in half the tests.
    4. In some cases, using HHVM as a nginx backend (i.e. not as a CLI) gives an even greater increase - apparently due to the activation of JIT. Notice how much faster the complex getid3 and TCPDF libraries work.


    CMS Testing



    Wordpress


    The fact that Wordpress runs on HHVM was known in advance . Only a small adjustment in one file is needed.

    Simple test: loading the main page 100 times in one stream.
    nginx + HHVM: 4.498 with
    Apache + mod_php: 9.997 c
    Apache + mod_php + APC: 6.567 c
    nginx + php-fpm + APC: 5.460 s

    I draw your attention to the fact that this was a test of page response time, and not load testing in several threads .

    Bitrix and Joomla


    Bitrix and Joomla on HHVM refused to start, giving a fatal error. I suspect that Bitrix has no hope of launching at all, because Deprecated functions and mbstring.func_overload are used there.

    A review of the Internet showed that while Worpress is the easiest way to run under HHVM. With other CMS and frameworks, everything is not so rosy, for example, in a recent topic on Habr, Symfony2 did not take off .

    Perhaps for those for whom performance is very important, you should immediately write a framework for HHVM?

    conclusions


    1) HHVM gives a good performance boost on some tasks - it is possible to use it to start background processing processes of something. Remember that HHVM is not effective when using global variables.

    2) Currently, using existing libraries, frameworks and CMS with HHVM is difficult. HHVM is sharpened for performance and may not support various beautiful designs. However, in the future the situation will improve, as and HHVM may begin to support a better language and developers may be puzzled by adapting their code to HHVM.

    3) On Wordpress, HHVM showed an impressive performance increase - 2 times compared to mod_php.

    PS test scripts , raw data (Excel)

    Also popular now: