Facebook’s HHVM Speeds Up Box

By David Cohen 

HHVMHackLogos650Thinking outside of the box worked for Box, as Joseph Marrama, a software engineer at the file-sharing and cloud content-management service, described in a blog post how Facebook’s HipHop Virtual Machine open-source PHP runtime allowed it to boost the speed of its applications.

Marrama wrote:

At Box, we’ve had our collective eye on the HipHop Virtual Machine (HHVM) for a while now. HHVM is Facebook’s open-source PHP runtime, and it differentiates itself from the standard PHP runtime on a key metric: speed. Whereas the standard PHP runtime is a run-of-the-mill interpreter, HHVM employs just-in-time compilation to enable significant gains in performance. Over the past few years, we’ve made a few different attempts at migrating our PHP codebase to run on top of HHVM. We currently have hundreds of thousands of lines of code and hundreds of contributors to our ever-growing PHP Web app, and historically, they have not interacted well with HHVM. But just under a year ago, the HHVM team’s growing focus on parity with the standard PHP runtime caught our attention. We decided to seriously re-evaluate HHVM, and, after a couple of months spent working through GitHub issues and runtime differences, often with Facebook’s HHVM team directly, it was clear that we were on to something big.

Many months in the making, Box is now in the process of deploying HHVM to our live Web app. The performance gains we’re seeing with HHVM exceeded all expectations: In testing, our average request latency dropped by a factor of three. This latency is measured as the time between when a request enters our infrastructure and when it leaves, which includes time spent in our PHP code base, as well as time spent talking to various back-end services.

The road to HHVM wasn’t without bumps or unexpected detours, though. After using Apache to run our PHP code base for seven years, our architecture and processes had ossified around the standard PHP runtime. Additionally, since PHP is a massive and dynamic language, we ran into use cases that HHVM had not used or built for. Replacing these components and contributing bug fixes back to HHVM as our architecture and code base surfaced them were significant tasks.

The migration also required a revamp of our deployment system. Since HHVM is a JIT compiler, it introduces a requirement to run new code a few times before all of the performance gains can be realized. Thus, when deploying new instances of HHVM, they have to “warm up” and cycle through code before going live. This detail, however small, necessitated an internal operational change in how we deploy new code.

Almost every request that touches Box goes through our PHP code base, so the speed increase is felt almost everywhere — our Web app, our sync client, our mobile apps and our application-programming interface. Box also stands to make very large savings in infrastructure costs over the years. We see this deployment as an important step for Box and one that will continue to optimize our service. As long as our PHP Web app exists, we will continue to see performance benefits from HHVM.

Advertisement
Advertisement