The “dynamically typed” programming language presented unprecedented opportunities for Facebook developers to build and rebuild the site, as Mark Zuckerberg puts it,”The Hacker Way”. However, it eventually ended up losing all the knack for rapid-fire development and succumbed to the intense workload of millions of users visiting the site every minute.
Then they invented HipHop, a tool that converts PHP script into C++ prior to compilation and execution on Web servers. This single – and by no means simple – change increased server capacity to accommodate a 500 to 600 percent increase in web traffic. In simple business terms, Facebook saved five to six times on server cost because of changing the way the code was run.
However, the HipHop beat couldn’t last long enough and Facebook needed yet another engineering breakthrough to accommodate its exploding web traffic. The team eventually developed the HipHop Virtual Machine (HHVM), a system that uses Just-In-Time (JIT) compilation to convert PHP code into a machine language to establish a synergy between the PHP code and the underlying hardware that runs it. A recent Kinsta post covers the rise and evolution of HHVM at Facebook.
The virtual machine was eventually made available for the WordPress world as an open source execution engine for PHP code promising similar performance improvements over the traditional PHP execution engine, Zend.
The PHP community is now responding to the HHVM competition with PHP 7, the latest PHP iteration promising 100 percent increase in performance over previous PHP versions. Feature speculations and possible enhancements for PHP 7 include:
The art of programming is changing rapidly and business organizations need to tap into the mobile user-base with better value propositions. In this context, PHP 7 will feature a range of execution engine improvements, offer native local threat storage and reduce memory usage.
These advantages serve particularly well for mobile devices with limited Web browsing capabilities. The upcoming PHP version also supports the idea of a greener planet with the ability to handle more traffic within the same server resources.
Zeev Suraski, co-founder of Zend Technologies considers HHVM as a direct competitor to the Zend execution engine and demonstrates how far the next generation PHP version has evolved in terms of performance improvements.
JIT Engine Speculation
The ability to implement JIT execution capabilities for the Zend engine is the prime motivation behind the development of next-generation PHP language version. These capabilities enable dynamic compilation of Zend opcodes into native machine instructions, the key principle driving performance with the HHVM engine.
As things stand, PHP 7 is on par with HHVM without JIT compilation capabilities featuring built-in with the Zend engine. However, PHP 7 is essentially repurposed to support better migration to a JIT compiler and promises even better performance improvements in years to come.
Asynchronous Programming Speculation
PHP 7 is developed in a way that facilitates simultaneous execution of asynchronous tasks. This capability will allow future iterations of PHP to support asynchronous programming and tasks such as access to database, networks, timers and perform events related I/O operations by implementing a single PHP event-loop.
Since the Facebook Hack language for HHVM already supports asynchronous programming, PHP core developers could see the same option made available for PHP 7 or its future iterations. This article covers a range of syntax changes expected for PHP 7.
Similarly, supporting standalone multi-threading further will further allow PHP-based servers to handle simultaneous requests from a single memory pool.
The following benchmark results compare the performance of various PHP versions and HHVM conducted across different content management systems:
Text Box Specs:
The test results demonstrates significant performance improvements with PHP 7 over its previous iterations, shrinking the persistent gap between PHP and HHVM. Running on WordPress 4.1.1, PHP 7 allows the system to execute twice as many requests per second in comparison with the PHP 5.6, the latest stable release.
Benchmarks conducted on the Drupal 8 CMS present PHP 7 as a clear winner over HHVM with the ability to handle over 37 percent additional server requests per second. In comparison with PHP 5.4, 5.5 and 5.6 that provided minimal performance through the subsequent iterations, PHP 7 accommodated over 80 percent additional requests per second.
This tests also presents PHP 7 with Zend execution as a better performing package than HHVM for CMS including WordPress and Drupal
Benchmarks conducted on Ubuntu Utopic package 5.5.12 compared the performance of PHP and HHVM in running a few basic test suites:
These benchmark results show interesting difference in between HHVM and PHP. PHP 7 is able to conduct the tests in 164.844 seconds with peak memory consumption of 30.879 MB. In contrast, HHVM performs the test twice as fast (84.759 seconds) but consumes 4.5 times more system memory (134.844 MB).
You can review our recent real-world benchmark comparisons between the latest iterations of PHP and HHVM on this article.
HHVM at ETSY
The peer-to-peer e-commerce giant Etsy having racked up over $108 million in annual revenue with 54 million registered users needed a serious revamp of its underlying technology infrastructure overwhelmed with millions of visits on a daily basis. Etsy engineers needed to improve the online service performance and boost backend data center efficiencies.
The company adopted the open-source HHVM solution to run PHP applications to maximize performance potential of the existing hardware infrastructure without having to invest in additional data center resources.
Etsy was most concerned with their new internal API to handle greater throughput so that servers could process more computing requests, consume less power and shrink operational expenses. Etsy engineers tested HHVM against PHP 5.4 by randomly splaying requests across three API endpoints, starting from 10 requests per second and ramping up to 280.
The benchmark results show how PHP experienced exponential performance degradation from 190 requests per second onward. At the same time, HHVM consistently demonstrated high performance until reaching 280 requests per second.
HHVM also optimized CPU time and required half as much CPU cycles as compared to PHP running exactly the same Web traffic profile and was also more efficient at communicating with backend services:
HHVM at Wiki
Almost half a billion Internet users visit Wikimedia every month. The website embodies the true philosophy of Internet as a means to share information free and accessible to the wider world. Bringing this ideology to life effectively requires the company to serve this information to end-users at reasonable speed.
Operating on a minimal budget and staff, the Wikimedia Foundation was forced to employ innovative solutions to boost backend server performance and capacity. Installing additional servers would only bottleneck performance since PHP as a single-threaded language cannot be parallelized. On the other hand, HHVM can load multiple CPU cores simultaneously to maximize the performance potential of servers.
Wikimedia achieved the following performance advantages by deploying HHVM:
- CPU load shrunk from 50 percent to 10 percent.
- Mean Page Save Time halved from six seconds to three seconds. This time is the interval between users hitting the ‘submit’ or ‘preview’ button and the server processing this request. Wikimedia received over 100 million edit requests in 2014 and HHVM will now help save around 10 years of latency every year.
- Median Page Save Time reduced by two thirds, from 7.5 seconds to 2.5 seconds.
- Average Page Load Time also dropped, from 1.3 seconds to 0.9 seconds.
Lessons Learned So Far…
Website performance is the crucial element of successful online presence. Progressive business organizations design systems to optimize innovation, which is all about delivering better, intelligent and useful online services faster than ever before.
While we have to wait for the stable release of PHP 7 to true winner in the HHVM vs PHP 7 battle, developers and online businesses can rely on the following key findings based on private benchmark results from various developers and companies:
- HHVM is significantly faster than PHP-Zend packages for all PHP versions prior to PHP 7 or PHPng (PHP Next Generation).
- PHP 7 has a slight edge against HHVM for WordPress set-ups. WordPress users should expect PHP 7 to improve and extend this advantage in the near future.
- The switch to HHVM is not push-button. Large environments such as Etsy and Wikimedia Foundation took over six months to fully switch from the PHP-Zend package to PHP-HHVM package. For self-hosted websites, the complex transition requires in-house expertise and may cause disruptions until thoroughly completed.
- Online businesses should choose between PHP 7 and HHVM sooner than later, lest they continue to incur significantly higher datacenter OpEx and risk losing valuable brand image due to inadequate website performance.
Performance optimization of PHP-based WordPress websites is an ongoing process yielding small chunks of incremental improvements. Injecting performance enhancing capabilities in the form of add-on plugins and minor code changes eventually fail to improve performance bottlenecked due to limited capabilities of the underlying PHP code-base and infrastructure.
Any further performance improvements – of 100 percent or faster – will be attributed to the server capacity and capabilities to process computing requests at higher rates. Both HHVM hosting and PHP 7 make this possible.
What is your experience with using HHVM? I’d love to hear your thoughts in the comments below.