Under the hood: Box’s HHVM migration

Visit the post for more.

16 min readintermediate
--
View Original

Overview

The article discusses Box's migration to HHVM (HipHop Virtual Machine) to enhance performance and reduce latency in their PHP application. It details the challenges faced during the migration, the operational changes required, and the significant performance improvements achieved post-migration.

What You'll Learn

1

How to effectively migrate a large PHP codebase to HHVM

2

Why using a JIT compiler can significantly improve application performance

3

How to manage deployment strategies for PHP applications using HHVM

4

When to implement automated testing to ensure compatibility during migration

Prerequisites & Requirements

  • Understanding of PHP and its runtime environments
  • Experience with large codebases and deployment strategies

Key Questions Answered

What are the main benefits of migrating to HHVM?
Migrating to HHVM resulted in a significant reduction in server-side latency by a factor of 2.5 and a drop in CPU utilization by over 2x. These improvements allow for better user experience and increased efficiency in resource usage, translating to cost savings.
What challenges did Box face during the migration to HHVM?
Box encountered several challenges, including unexpected incompatibilities between HHVM and the default PHP interpreter, the need to revamp their deployment strategy, and ensuring smooth operation in a mixed environment with both HHVM and Apache. These challenges required careful testing and adjustments.
How does HHVM's JIT compilation improve performance?
HHVM's JIT (Just-In-Time) compilation compiles frequently executed PHP code down to assembly, allowing for faster execution compared to traditional PHP interpreters. This leads to significant performance gains, as demonstrated by HHVM running core endpoints over four times faster than the default PHP interpreter.
What deployment strategies are recommended for HHVM?
Box adopted a strategy of maintaining multiple HHVM instances to handle traffic while allowing for code warm-up and regular restarts. This approach facilitates smooth rollouts, easy rollbacks, and canary deployments, ensuring high availability and performance.

Key Statistics & Figures

Reduction in server-side latency
2.5 times
This reduction was observed after rolling out HHVM to the majority of Box's infrastructure.
Drop in CPU utilization
over 2x
This improvement provided Box with increased frontend capacity without additional costs.
Performance increase for core endpoint
over 4 times faster
This was the result of initial experiments comparing HHVM to the default PHP interpreter.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Hhvm
Used as the exclusive engine to serve Box's PHP codebase.
Backend
Php
The primary language used in Box's web application.
Memory Allocation
Jemalloc
HHVM's preferred memory allocation library, which impacts memory usage reporting.

Key Actionable Insights

1
Implement a robust testing framework before migrating to HHVM to catch compatibility issues early.
Automated testing was crucial for Box to identify runtime differences between HHVM and the default PHP interpreter, preventing user impact during the migration.
2
Adopt a multi-instance deployment strategy to ensure high availability during code updates.
By using multiple HHVM instances, Box was able to warm up new code and roll back to previous versions seamlessly, minimizing downtime and user disruption.
3
Monitor error logs closely during the rollout to catch new issues promptly.
Box extended their error monitoring system to include HHVM logs, which helped identify and triage new errors that could arise from the migration.

Common Pitfalls

1
Underestimating the impact of behavioral differences between HHVM and the default PHP interpreter.
Box faced numerous runtime discrepancies that required extensive testing and adjustments. Failing to account for these differences could lead to significant issues in production.
2
Neglecting to warm up HHVM before serving live traffic.
HHVM's JIT compilation requires initial runs of new code to optimize performance. Without this step, applications may not perform optimally right after deployment.

Related Concepts

Php Performance Optimization
Jit Compilation Techniques
Deployment Strategies For Web Applications
Automated Testing Best Practices