mpen
mpen

Reputation: 283273

Vagrant+Ubuntu 14.04+Nginx+HHVM = slow + crashing

As per my last question, I'm trying to speed up Laravel by running it under HHVM.

This required me to update my server to 64-bit, so I'm running Trusty64 now. I installed HHVM and Nginx via deb packages. I'm not entirely sure my nginx configuration is right, I scraped this off the net:

server {
    listen 80 default_server;

    root /vagrant/public;
    index index.php index.html index.htm;

    server_name localhost;

    access_log /var/log/nginx/localhost.laravel-access.log;
    error_log  /var/log/nginx/locahost.laravel-error.log error;

    charset utf-8;

    location / {
        try_files \$uri \$uri/ /index.php?\$query_string;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }

    error_page 404 /index.php;

    include /etc/nginx/hhvm.conf;  # The HHVM Magic Here
}

And my site does load the first few times I hit it. It's now taking more than twice as long to load than with the built-in PHP server. After several refreshes, the page stops loading altogether, nginx gives a 504 gateway timeout, I can no longer SSH in to my server, and vagrant takes several minutes just to shut down. Whatever it's doing, it's completely killing my server.

I heard HHVM uses some kind of JIT and requires warming up, then kicks in after several loads? Could this be what's destroying my server? How do I fix that?

Upvotes: 3

Views: 2524

Answers (1)

Ray
Ray

Reputation: 41498

Post Update: I must eat my words!!!! I moved the laravel code from a share virtual box folder to a non-shared directory, now HHVM loads the laravel welcome screen in less than 10ms once JIT kicks in.

There is a startup config setting that indicates the number of request needed before HHVM JIT kicks in.

Here's the ini file I use for my HHVM:

 pid = /var/run/hhvm/pid

 hhvm.server.file_socket=/var/run/hhvm/hhvm.sock
 hhvm.server.type = fastcgi
 hhvm.server.default_document = index.php
 hhvm.log.level = Warning
 hhvm.log.always_log_unhandled_exceptions = true
 hhvm.log.runtime_error_reporting_level = 8191
 hhvm.log.use_log_file = true
 hhvm.log.file = /var/log/hhvm/error.log
 hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
 hhvm.mysql.typed_results = false

 hhvm.eval.jit_warmup_requests = 1

The jit_warmup_requests = 1 indicates one reload before optimization, but you can set it to 0 for it to immediately kick in. I think if not specified, it's like 10 requests or something.

Regardless, I've the same setup as you, nginx, hhvm 3.0.1, laravel, Ubuntu 14, on a VirtualBox image using a shared folder. I use the same shared folder with a second image running PHP-FPM5.5. The PHP-5.5 loads the laravel 'you have arrived' page in 50ms or so, while the HHVM version is more on the order of 250ms--much less perfomance than expected. I'm going to test running the code in a non-shared directory, but I doubt this is the issue.

I suspect it has to do with the amount of code that must be evaluated at runtime vs. compile time. I know if I run code with lots of magic methods and variable-variables HHVM doesn't exactly shine. Laravel has some funky autoloading going on to achieve it's hiding of namespaces and such and this might have some impact, but I'd need to go deeper to make a strong stand on this.

I have this in my nginx config file to pass scripts to HHVM (note I use sockets, not TCP and don't use hack yet.)

      location ~ \.php$ {
            fastcgi_pass unix:/var/run/hhvm/hhvm.sock;

            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
         }

Upvotes: 2

Related Questions