简体   繁体   English

Vagrant + Ubuntu 14.04 + Nginx + HHVM =慢+崩溃

[英]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. 根据我的上一个问题 ,我试图通过在HHVM下运行来加速Laravel。

This required me to update my server to 64-bit, so I'm running Trusty64 now. 这要求我将服务器更新为64位,所以我现在正在运行Trusty64。 I installed HHVM and Nginx via deb packages. 我通过deb软件包安装了HHVM和Nginx。 I'm not entirely sure my nginx configuration is right, I scraped this off the net: 我不完全确定我的nginx配置是对的,我把它从网上删除了:

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. 现在加载的时间是内置PHP服务器的两倍多。 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. 几次刷新后,页面完全停止加载,nginx给出504网关超时,我不能再SSH到我的服务器,并且vagrant需要几分钟才能关闭。 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? 我听说HHVM使用某种JIT并且需要预热,然后在几次加载后启动? Could this be what's destroying my server? 这可能是什么摧毁了我的服务器? How do I fix that? 我该如何解决这个问题?

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. 我将laravel代码从共享虚拟框文件夹移动到非共享目录,现在HHVM在JIT启动后在不到10ms的时间内加载了laravel欢迎屏幕。

There is a startup config setting that indicates the number of request needed before HHVM JIT kicks in. 有一个启动配置设置,指示在HHVM JIT启动之前所需的请求数。

Here's the ini file I use for my HHVM: 这是我用于HHVM的ini文件:

 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. jit_warmup_requests = 1表示在优化之前重新加载,但您可以将其设置为0以使其立即启动。我认为如果未指定,则类似于10个请求或其他内容。

Regardless, I've the same setup as you, nginx, hhvm 3.0.1, laravel, Ubuntu 14, on a VirtualBox image using a shared folder. 无论如何,我使用共享文件夹在VirtualBox图像上使用与您,nginx,hhvm 3.0.1,laravel,Ubuntu 14相同的设置。 I use the same shared folder with a second image running PHP-FPM5.5. 我使用相同的共享文件夹和运行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. PHP-5.5在50ms左右的时间内加载了“你已到达”的laravel页面,而HHVM版本则大约为250ms - 比预期的性能要低得多。 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. 我知道如果我运行代码有很多魔术方法和变量变量HHVM并不完全闪耀。 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. Laravel有一些时髦的自动加载,以实现它隐藏名称空间等等,这可能会产生一些影响,但我需要更深入地对此做出坚定的立场。

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.) 我在我的nginx配置文件中有这个将脚本传递给HHVM(注意我使用套接字,而不是TCP,不要使用hack。)

      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;
         }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM