Skip to content

Instantly share code, notes, and snippets.

@gondo
Forked from SchumacherFM/Magento-HHVM.md
Created August 17, 2013 03:15
Show Gist options
  • Select an option

  • Save gondo/6255074 to your computer and use it in GitHub Desktop.

Select an option

Save gondo/6255074 to your computer and use it in GitHub Desktop.
PidFile = /tmp/hhvm.pid
Server {
Port = 8080
SourceRoot = /var/www/customer/site
# DefaultDocument = index.php
}
AdminServer {
Port = 8088
ThreadCount = 1
Password =
}
Eval {
Jit = true
}
Log {
NoSilencer = true
Header = true
Level = Verbose
UseLogFile = true
AlwaysLogUnhandledExceptions = true
RuntimeErrorReportingLevel = 8191
File = /var/log/hhvm/error.log
Access {
* {
File = /var/log/hhvm/access.log
Format = %h %l %u %t \"%r\" %>s %b
}
}
}
VirtualHost {
* {
Prefix = customer.local
ServerVariables {
MAGE_IS_DEVELOPER_MODE = true
MAGE_RUN_CODE = customer_de
MAGE_RUN_TYPE = store
PHP_SELF = /de/index.php
SCRIPT_NAME = /de/index.php
}
RewriteRules {
dirindex {
pattern = ^/(de|fr)/(.*)
to = $1/index.php/$2
qsa = true
conditions {
* {
pattern = \.(css|js|jpg|png|gif)$
negate = true
}
}
}
}
}
}
StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
Extensions {
woff = application/x-font-woff
js = text/javascript
css = text/css
gif = image/gif
html = text/html
jpe = image/jpeg
jpeg = image/jpeg
jpg = image/jpeg
png = image/png
tif = image/tiff
tiff = image/tiff
txt = text/plain
}
}
#!/bin/bash
hhvm --user vagrant -c /var/www/customer/hhvm.hdf --mode daemon
# to analyze
# find /var/www/customer/site -name '*.php' -o -name '*.phtml' > /tmp/customer_files.txt
# find /var/www/customer/site -name '*.php' > /tmp/customer_files.txt
# hhvm --hphp -t analyze --gen-stats=1 --keep-tempdir=1 --input-list /tmp/customer_files.txt --output-dir=/tmp/hphp

Running Magento Enterprise Edition with Facebook HipHop HHVM

Prerequisites

Hardware

MacBook Air (MBA) Mid 2012

Virtualbox (VB): Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-23-generic x86_64) via vagrant.

Software

MBA with Apache 2 with mod_php Version 5.3.19 with MySQL 5.5 (MAMP)

VB with fresh pulled HHVM sources with MySQL 5.5

Magento

I ran here a big customized Magento EE 1.12 store from a big Swiss scout store. A lot of custom price rules for many different groups and some fancy discount types.

URL schema is different from the official demo store: www.customer.ch/[de|fr]/index.php to map automatically different languages.

Magento Cache activated. MySQL database slightly optimized via mysqltuner.pl

  • 5000 SKUs
  • 237 categories
  • 48.000 url rewrites
  • 4 store views
  • FPC disabled

Magento EE sources has been imported into the VM. Not via shared folders or NFS. There were previously some weird long request times with HHVM when using shared folders.

Compile and Download HipHop

You can use the install script install-hhvm.sh for compiling and installing hiphop https://github.com/jakoch/php-hhvm.

But change the hiphop source in function get_hiphop_source() to the special Magento hiphop https://github.com/danslo/hiphop-php source.

Optionally: You can remove all the last lines after ## Success in the script install-hhvm.sh.

Official FB "How to" compile: https://github.com/facebook/hiphop-php/wiki

Prebuild packages will not work with Magento.

HHVM config.hdf

Options for the config.hdf file: https://github.com/facebook/hiphop-php/blob/master/hphp/doc/options.compiled

Please see the to this gist attached file hhvm.hdf.

Buggy is the PHP_SELF and SCRIPT_NAME which will not be properly set therefore hardcoded. Also the rewrite rules can be more optimized.

Magento Errors

I'm not quite sure if that is still a problem with SimpleXML or with buggy Magento code.

Fixes:

  • File site/app/code/core/Mage/Core/Block/Template/Facade.php every: $key = (string)$key;

Unfixable:

  • There are also some errors in the site/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 441 but that results from strange code in phtml files ... 8-)

Not every category will work but 98% of them.

Search

Not possible due to HHVM shows this error:

Notice: Undefined index: 0 in /var/www/customer-dev/site/app/code/core/Mage/Catalog/Model/Layer/Filter/Price/Algorithm.php on line 368

There is something weird in our code base, not in HHVM.

Performance Test

Multiple shift-reloads in the FF 23 browser in two tabs. Times are approximate.

Request Type 			HHVM		MAMP	MAMP-APC [1]
CMS Page				450ms		2.5s	820ms
Category View [2]		980ms		4.6s	3.5s
Product View [3]		500ms-1s	4.7s	3.1s
Add to basket [4]		1.2-2.9s	8.8s	5.5s
List basket [5]			2.1s		6.9s	3.8s
List basket [6]			1s			5.5s	2.9s
Checkout Onepage [7]	690ms		4.47s	
Onepage SaveBilling		236ms		2.3s
Onepage SaveShipping	251ms		2.4s
Onepage SavePayment		486ms		3.28s
Onepage success			562ms		3.25s
  1. MAMP-APC runs with PHP 5.4.16
  2. containing 8 products
  3. configurable product with two options and one customer rating
  4. POST to cart with redirect to product view and listing cart content
  5. First call of the basket page
  6. Reloads
  7. Initial load of the page checkout/onepage after that normal checkout process

ab -n 20 -c 5

MAMP-APC HHVM
`Concurrency Level: 5
Time taken for tests: 23.229 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 2202440 bytes
HTML transferred: 2193600 bytes
Requests per second: 0.86 [#/sec] (mean)
Time per request: 5807.239 [ms] (mean)
Time per request: 1161.448 [ms] (mean, across all concurrent requests)
Transfer rate: 92.59 [Kbytes/sec] received` `Concurrency Level: 5
Time taken for tests: 7.334 seconds
Complete requests: 20
Failed requests: 0
Write errors: 0
Total transferred: 2244160 bytes
HTML transferred: 2235640 bytes
Requests per second: 2.73 [#/sec] (mean)
Time per request: 1833.474 [ms] (mean)
Time per request: 366.695 [ms] (mean, across all concurrent requests)
Transfer rate: 298.83 [Kbytes/sec] received`

Conclusion

Facebook is working hard on HHVM. A lot of commits take place every day!

Big kudos to https://twitter.com/daniel_sloof for fixing HHVM errors related to Magento!

That would be one future for PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment