VKCOM / kphp

KPHP — a PHP compiler
https://vkcom.github.io/kphp/
GNU General Public License v3.0
1.34k stars 88 forks source link

Slower than PHP+Swoole ! #1063

Closed henrywood closed 1 month ago

henrywood commented 1 month ago

Because I did a benchmark for Swoole last year, I thought I would try to do a similar one for KPHP.

The Swoole benchmark showed between 330000-360000 requests per second on my small laptop for a simple "HELLO" HTTP webserver.

So I compiled this code:

<?php

echo "HELLO".PHP_EOL;

which does the same thing as the Swoole benchmark (although a bit more involved when using Swoole)

Compiling it with:

# kphp test.php --mode server -o ./test

Running it with:

# ./test --workers-num 8 --user henrik --daemonize --small-acsess-log=2 --http-port 8100 &

Running the benchmark:

# wrk -t100 -c500 -d10s http://localhost:8100/

Here are the results

Running 10s test @ http://localhost:8100/
  100 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    21.16ms   18.68ms 353.66ms   95.80%
    Req/Sec   499.68    154.72     1.44k    78.50%
  490122 requests in 10.10s, 78.99MB read
  Socket errors: connect 79, read 0, write 0, timeout 0
Requests/sec:  48537.00
Transfer/sec:      7.82MB

It looks like KPHP is a full 7 times slower than Swoole+PHP ???

I did not expect this ?

I know that this is a simple I/O-bound test and I would expect benchmarks to be more equal when doing CPU-bound work ?

(Remember that Swoole is a PHP extension) but when running it is just plain uncompiled PHP)

Any ideas why KPHP is this much slower ???

apolyakov commented 1 month ago

Hi, KPHP needs to do a lot of work on initialization. That's why in some cases it may be slower that plain PHP. You may take a look at dedicated page about benchmarking KPHP: https://vkcom.github.io/kphp/various-topics/walk-through-php-kphp-cpp.html

henrywood commented 1 month ago

Thank you for the reply.