HHVM poor performance
Asked Answered
N

3

43

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

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

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    

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

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?

Nibble answered 27/7, 2013 at 14:19 Comment(0)
E
101

HHVM engineer here.

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

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.

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.

There are a couple reasons to do this.

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

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.

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

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.

Electrostatics answered 28/7, 2013 at 21:55 Comment(2)
I am having extremely slow performance with my nginx setup. If you could give me any feed back on my thread #25147553Esurient
I could not solve from the data in answer. If anyone facing same concern then visit these threads: 1. github.com/facebook/hhvm/issues/3166 2. github.com/facebook/hhvm/issues/900 I was creating server without specifying config, where I was wrong.Kero
E
2

I have the same performance problem, and I get impressive results only after commenting these lines in /etc/hhvm/php.ini

;hhvm.log.level = Warning
;hhvm.log.always_log_unhandled_exceptions = true
;hhvm.log.runtime_error_reporting_level = 8191
Euphroe answered 19/3, 2015 at 12:32 Comment(0)
L
2

if HHVM > v3.4 Changed Eval.JitWarmupRequests=0 to Eval.JitProfileInterpRequests=0

`#!/usr/bin/hhvm -v Eval.Jit=1 -v Eval.JitProfileInterpRequests=0  ./do.php`
Laritalariviere answered 26/4, 2015 at 2:47 Comment(1)
where is that code to be changed? I can't seem to find the path to that file. any idea?Moir

© 2022 - 2024 — McMap. All rights reserved.