154 points · by jamesgpearce · 12y ago · 103 comments
Is the 15% performance increase relative to vanilla PHP or to a previous version of HHVM?
The 15% increase is relative to HHVM at the beginning of the 3-week sprint they just completed. HHVM was already far faster than vanilla PHP when it was first publicly announced over a year ago.
1. For simple code only - once it's more computationally intensive, HHVM wins. http://www.alexfu.it/2013/10/22/symfony-benchmark-on-hhvm.ht...
2. http://blog.liip.ch/archive/2013/10/29/hhvm-and-symfony2.htm...
I'm pretty happy with it. Is it worth it? Well, if you've got a test suite, run it through HHVM to see if you'll have any issues. If the answer is no, then why turn down free performance :)
I use Nginx as frontend and direct all dynamic request to HHVM's own webserver (https://github.com/facebook/hhvm/wiki/Using-nginx-as-Front-S... )
Keep in mind, Facebook runs on HHVM too, so it's rock solid.
Btw. the devs are very helpful on the official irc channel!
HipHop took PHP code and basically turned it into a statically compiled C++ application. The resulting binary acted directly as a web server. It was pretty fast, but very limited.
HHVM is an actual JITing virtual machine for PHP. It's still huge (one of the project pages say that the binaries are nearly a hundred megs), but it's now a real-world reimplementation of PHP, capable of doing anything PHP can, including eventually being run by mere mortals with normal code.
Now if only the rest of the PHP devs stuck in 2005 would switch to it...
The really cool part though, it truly was "drop in". Every bit of my existing nginx/fpm configs worked as is, so once it's a bit further along, it's just a matter of shutting down fpm and firing up HHVM.
There were also a couple of gotchas in the setup related to the fact that their apt installer installed HHVM configs that don't assume Fastcgi, so it took a little bit to figure out the correct edits to the init script and HHVM config so it'd listen on :9000 instead of :80, but all in all that it worked at all was really fun for a minute. Very excited about this project.
compare:
php 5.5: https://travis-ci.org/laravel/framework/jobs/15683979
First read the page related to your Linux/BSD e.g. "Prebuilt Packages on Ubuntu 12.04"
Then read the page "Using nginx as Front Server to HipHop"
As last step read this blog article how to write/edit the config file (/etc/hhvm.hdf): http://www.hhvm.com/blog/113/getting-wordpress-running-on-hh...
Read this and copy things you need from the documentation: https://github.com/facebook/hhvm/blob/master/hphp/doc/option...
This is how I got HHVM working.
To sum up:
* you need a little bit of basic Linux knowledge
* install Linux or BSD (e.g. Ubuntu 12.04 LTS) (64-bit)
* install Nginx (or since last week HHVM also supports Apache with FastCGI)
* install HHVM
* install MySQL or MariaDB, etc.
* create a web directory where you place your php files
* edit the hhvm.hdf (config file)
* start hhvm
Btw. a lot of blog posts you find with Google search are still about the old HpHp (the former and now outdated PHP to C++ translator also called HipHop from FB)... so better skip third party blog posts older than January 2013 ;)E.g. XMLHttpRequest vs ExtensibleMarkupLanguageHypertextTransferProtocolRequest
and ftp_ssl_connect vs FileTransferProtocol_SecureSocketLayer_Connect
or if you want to get really ridiculous:
MysqlndUhConnection::sslSet becomes MyStructuredQueryLanguageNativeDriverUserHandlerConnection::SecureSocketLayerSet
e.g.
function findFirst ($haystack, $needle, $before_needle=false, case_sensitive=false) {
if (case_sensitive) {
return stristr($haystack, $needle, $before_needle);
}
return strstr($haystack, $needle, $before_needle);
}
You can submit them as RFC to https://wiki.php.net/rfc and maybe your suggestion end up in a future version of PHP. As PHP code in HHVM is almost as fast as C++ code, your wrapper functions will be still useful for you in the meantime.The problem is speed and compatibility. If you did it natively you'd have to do it twice, once for HHVM and once for the Zend engine. If you did it in pure PHP it would cause performance issues since the interpreter isn't smart enough to inline (maybe HHVM is, but even it will take a trace or two to realize the JIT need probably).
$foo = 'bar';
echo $foo->length(); // 3
echo strlen($foo); // 3
This would get rid of a lot of the confusion around string function names.Basically, if you use PHP you're part of the largest computer joke in history.
I have no problem with using either PHP or Python on a particular project, depending on what is involved. I wish PHP threads would show a bit more maturity/pragmatism on both sides of the aisle sometimes.
http://yougov.github.io/pycon/slides/
http://highscalability.com/blog/2012/3/26/7-years-of-youtube...
http://www.slideshare.net/jinaljhaveri/scaling-python-webapp...
http://blog.disqus.com/post/62187806135/scaling-django-to-8-...
I was thinking of recording the production requests for x amount of time and replaying them on HHVM so you could see if responses are identical, there are no crashes, state of the database is same afterwards, etc.?
Seriously though, I decided that if I had a project that was difficult to test, that I knew had hairy code that used some funky features it was best to just stick to APC. All my new projects are being built on HHVM directly with test suites as I go.
Edit; that was a while back now, though. What frameworks and libraries are you using? Run their test suites through HHVM and if they all pass, you'll be fine. Facebook use it themselves now apparently.
Another idea once you're reasonably comfortable and have done a smoke test is to direct a small amount of your traffic/users (say 1%) to the HHVM version, while closely monitoring its error log.
There generally aren't a lot of status meetings, team meetings, project meetings, and so forth at Facebook, but you might want to turn down a request to present at another team's meeting, or turn down those requests to interview - they can wait, or another person can be found.
People tend to make progress on lower-priority work items in between higher-priority work items - things like migrating onto a new library or version of a service, or maybe migrating from one set of machines to another if you aren't using one of the high-level service management systems. This is necessary to prevent these things from becoming interrupt items down the line, but during a lockdown period, it's okay to let these slide for a bit.
If the whole team does this, then suddenly you're spending a lot more time together. Instead of potentially working on different parts of the software like you usually do, you can all focus on a particular class of problem - in this case, performance and parity. That means everyone has that context loaded up, and you can have better discussions and quicker code reviews.
https://github.com/facebook/hhvm/blob/master/hphp/test/frame...