HHVM 性能不佳 [英] HHVM poor performance

查看:45
本文介绍了HHVM 性能不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估 HipHop-PHP 在我们的代码库上的兼容性和性能,但在启用内置网络服务器的情况下运行它时性能非常差.

I'm evaluating HipHop-PHP for compatibility and performance on our code base, but I'm getting very poor performance when running it with the built-in web server enabled.

我有以下示例测试程序来计算斐波那契数列.

I have the following sample test program that calculates a Fibonacci sequence.

ex3.php:

function fib($n)
{
    if ($n <= 2)
        return 1;
    else
        return fib($n-1) + fib($n-2);
}

$n = 36;
printf("fib(%d) = %d\n", $n, fib($n, 2));

当我使用命令行通过 HHVM 运行它时,我得到了令人印象深刻的结果:

When I run this through HHVM using the command-line, I get impressive results:

time hhvm -v"Eval.Jit=true" -f ./ex3.php
fib(36) = 14930352

real    0m0.267s
user    0m0.248s
sys     0m0.020s

将其与标准 PHP 进行比较:

Compare this with standard PHP:

root@hiphop:/www# time php -f ./ex3.php
fib(36) = 14930352

real    0m5.606s
user    0m5.600s
sys     0m0.000s    

然而,当我想在 HHVM 中启用内置的 web 服务器时,所有的性能提升都将丢失:

However, when I want to enable the built-in web server in HHVM, all performance gains are lost:

hhvm -v"Eval.Jit=true" -m server -p 8000 &
time wget -qSO - http://localhost:8000/ex3.php
  HTTP/1.1 200 OK
  Content-Type: text/html; charset=utf-8
  X-Powered-By: HPHP
  Date: Sat, 27 Jul 2013 14:16:09 GMT
  Content-Length: 19
fib(36) = 14930352

real    0m5.279s
user    0m0.000s
sys     0m0.000s

如您所见,我正在从 HHVM 收到响应,但它处理此请求需要 5 秒以上的时间.我错过了什么?

As you can see, I'm getting the response back from HHVM, but it taks more than 5 seconds for it to process this request. What am I missing?

推荐答案

HHVM 工程师在这里.

HHVM engineer here.

在服务器模式下,HHVM 将运行它在仅解释器模式下(即关闭 JIT)看到的前 N ​​个请求.

In server mode, HHVM will run the first N requests it sees in interpreter-only mode (i.e. with the JIT off).

优化构建中的默认值是 N=11,因此如果您要运行请求 12 次,第 12 次会快得多.

The default in an optimized build is N=11, so if you were to run the request 12 times, the 12th one would be much faster.

您可以使用配置选项进行调整,如下所示:-v Eval.JitWarmupRequests=3.如果您将其设置为 0,您将立即看到加速.

You can tune this with a config option, like so: -v Eval.JitWarmupRequests=3. If you set it to 0, you'll see the speedup immediately.

这样做有几个原因.

首先,它可以防止瞬态预热效应影响 JIT 编译的代码.

First, it prevents transient warmup effects from affecting JIT-compiled code.

例如,前几个请求可能需要在 APC 中填充值,这将导致应用程序代码沿着与稳态路径不同的路径运行.这样,我们就不会在只会使用几次的 JIT 编译上浪费空间.

For example, the first few requests may need populate values in APC, which will cause the application code to go down different paths from the steady-state paths. This way, we don't waste space on JIT compilations that will only be used a few times.

其次,它允许 HHVM 收集分析信息以改进未来的编译.

Second, it allows HHVM to collect profiling information to improve future compilation.

例如,如果我们观察到某个值在 99% 的情况下是整数,我们就可以编译针对整数情况优化的代码.我们目前没有工具在启用分析的情况下对代码进行 JIT 编译(困难的部分是在我们完成后安全地将其丢弃),因此我们在仅解释器模式下进行数据收集.

If we observe that a certain value is an integer 99% of the time, for example, we can compile code that's optimized for the integer case. We currently don't have the facility to JIT-compile code with profiling enabled (the hard part is safely throwing it away once we're done with it), so we do the data collection in interpreter-only mode.

这篇关于HHVM 性能不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆