Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Daniel Sloof: Magento on HHVM


Published on

  • Be the first to comment

Daniel Sloof: Magento on HHVM

  1. 1. Magento on HHVM Speeding up your webshop with a drop-in PHP replacement.
  2. 2. Daniel Sloof
  3. 3. Some background Specification Ruby Language JRuby Rubinius IronRuby Java Language Oracle Harmony Dalvik Implementation Sensible Language Design Zend PHP PHP Language Zend PHP HHVM PHP
  4. 4. What is HHVM? ● HipHop Virtual Machine ● Created by engineers at Facebook ● Essentially a reimplementation of PHP ● Originally translated PHP to C++, now translates PHP to bytecode ● Just-in-time compiler, turning generated bytecode into machine code ● In some cases 5 to 10 times faster than regular PHP
  5. 5. Bytecode compilation ● PHP5 style bytecode Yes Modified? Invalidate cache Compile to Bytecode Run Bytecode No execution ● APC-like caching of bytecode ● Performance is quite similar to Zend PHP
  6. 6. Just In Time Compiler Modified? Have Native? Hot? Invalidate Cache Compile to Bytecode Compile to Native Run Bytecode Run Native No No Yes Yes Yes No
  7. 7. What was the problem? ● HHVM not entirely compatible with PHP ● Magento’s PHP triggering many of these incompatibilities ● Choosing between ○ Forking Magento to work around HHVM ○ Fixing issues within the extensive HHVM C++ codebase
  8. 8. Resulted in... fixing HHVM ● Already over 100 commits fixing Magento related HHVM bugs; ○ SimpleXML (majority of bugfixes) ○ sessions ○ number_format ○ __get and __set ○ many more... ● All of these patches already merged back into the official (github) repository ● Still actively involved and committed to make HHVM a good place for Magento
  9. 9. Resulted in... fixing HHVM Activity for the HHVM project on github in June “Of the top 15 contributors, only 9 are facebook employees.”
  10. 10. Important configuration ● hhvm.enable_zend_sorting = 1 ○ PHP user sorting “If two members compare as equal, their relative order in the sorted array is undefined.” ○ HHVM implements a faster sorting algorithm that has a different (undefined) order. ○ Magento relies on this undefined behavior. ● hhvm.enable_obj_destruct_call = 1 ○ HHVM by default does not call destructors for objects that are alive at the end of the request. ○ Magento Connect Downloader uses object destructors to send output to the browser.
  11. 11. What that means for Magento... ● Community and Enterprise Editions running stable. ● Passes near 100% of the Test Automation Framework. ● Large boost in improvement. ● Works with FastCGI, so keep most of your current web-configuration, rewrites, etc.
  12. 12. Benchmarks Before we go to the results... ● Magento 1.9 with sample data ● Standard nginx / php-fpm / percona stack (with PHP 5.5 opcode cache) ● Standard HHVM configuration (repo-authoritative mode disabled, JIT enabled) ● Tool of choice: siege
  13. 13. Benchmarks: Response time Average across 50 requests
  14. 14. Benchmarks: Transaction rate While increasing siege concurrency until avg. response time ~2 seconds
  15. 15. Benchmarks: Other
  16. 16. What about <insert caching solution here>? ● HHVM does not get in the way ● Dynamic content still needs to be generated ● Replaces PHP - not Varnish, Redis, FPC, Block Cache, etc. ● As long as you are burning CPU cycles (always), you will benefit from HHVM ● Think about speeding up indexing, order placement, routing, etc.
  17. 17. What about PHPNG / PHP7? ● Better performance than PHP5.5, but still trails behind HHVM quite significantly. ● Not ready.
  18. 18. How do we know it is stable? ● Unfortunately there are no unit tests for (core) Magento 1.x ● Brushed up the Test Automation Framework ● Automated setup of test environment using Chef ● Nightly builds to check Magento compatibility on HHVM to make it easier to spot regressions
  19. 19. On the topic of debugging ● HHVM comes with something called HPHPd ● CLI Based, comparable to GDB ● No (known) support for any IDEs Latest stable release has xdebug support!
  20. 20. What is Hack? Moving to HHVM gets even more awesome. ● Statically typed language ● Type annotations ● Generics ● Async ● Lambda’s ● Collections ● Built-in user attributes
  21. 21. Hack: Annotating
  22. 22. Hack: Constructor Argument Promotion
  23. 23. Hack: Special Attributes
  24. 24. What about the future? ● Facebook is committed to open source: several employees work on it exclusively. ● HHVM tracks a number of popular frameworks and runs their PHPUnit suites ● Magento 2 is part of that list
  25. 25. What about the future? Open Source Benchmark Suite ● Automatic installation of popular frameworks (Magento, Drupal, Wordpress, etc). ● Configures your web server ● Generates reliable performance metrics to compare PHP implementations (HHVM, PHP7).
  26. 26. What about the future?
  27. 27. Can we gradually migrate? Store not entirely compatible with HHVM and still want to run it. ● Problem is isolated to a (subset of) page(s): use web-server configuration to split load. ● Problem is more widespread (incompatible global observers, ioncube, etc):
  28. 28. Thank you! Questions?