rryqszq4 / ngx-php

ngx-php - Embedded php7 or php8 scripting language for nginx module. Mainline development version of the ngx-php.
BSD 2-Clause "Simplified" License
584 stars 56 forks source link

Try to add OPcache #72

Closed joanhey closed 4 years ago

joanhey commented 4 years ago

We could try that: https://bugs.php.net/bug.php?id=65078

And if work without problem, create a bug request to add the ngx_php7 sapi.

rryqszq4 commented 4 years ago

WechatIMG4243

@joanhey Not startup, I think need a add request~

rryqszq4 commented 4 years ago

The name is better with 'php-ngx' https://github.com/rryqszq4/ngx_php7/blob/master/src/php/impl/php_ngx.c#L263

joanhey commented 4 years ago

Had you tried to add "php-ngx" in https://github.com/php/php-src/blob/master/ext/opcache/ZendAccelerator.c#L2544 ??

Copile it to try with php-ngx.

rryqszq4 commented 4 years ago

I am trying something else.

joanhey commented 4 years ago

https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c

The uwsgi, perhaps they initialize the sapi in another way.

Also useful to take ideas.

joanhey commented 4 years ago

In nginx unit it's working without problems. https://github.com/nginx/unit/blob/master/src/nxt_php_sapi.c

They are using "cli-server" :roll_eyes:

We could try with that first.

rryqszq4 commented 4 years ago

I think that "cli-server" maybe better.

joanhey commented 4 years ago

With "cli-server" DeepinScreenshot_20191028170015

joanhey commented 4 years ago

I need to test a little more. With different files. This image is using the app.php loaded in the init_worker. So it is loaded only one time.

joanhey commented 4 years ago

I don't expect any exponencial gain. But all the includes outside of the init_worker will be fast now.

rryqszq4 commented 4 years ago

@joanhey Test use opcache and not.

  1. Result of use opcache

    ./wrk -H 'Host: 127.0.0.1' -H 'Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7' -H 'Connection: keep-alive' --latency -d 15 -c 512 --timeout 8 -t 28 http://127.0.0.1/h2
    Running 15s test @ http://127.0.0.1/h2
    28 threads and 512 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   109.19ms  538.96ms   6.81s    97.50%
    Req/Sec     1.77k     1.66k   10.61k    81.66%
    Latency Distribution
     50%    2.47ms
     75%    3.53ms
     90%  200.55ms
     99%    3.21s 
    627719 requests in 15.10s, 81.39MB read
    Socket errors: connect 0, read 10, write 0, timeout 4
    Requests/sec:  41570.54
    Transfer/sec:      5.39MB
  2. Result of not use opcache

    ./wrk -H 'Host: 127.0.0.1' -H 'Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7' -H 'Connection: keep-alive' --latency -d 15 -c 512 --timeout 8 -t 28 http://127.0.0.1/h2
    Running 15s test @ http://127.0.0.1/h2
    28 threads and 512 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   508.66ms    1.27s    7.91s    89.15%
    Req/Sec   198.26    158.90     1.46k    61.65%
    Latency Distribution
     50%   49.07ms
     75%   52.63ms
     90%    2.09s 
     99%    5.82s 
    30416 requests in 15.10s, 3.94MB read
    Socket errors: connect 0, read 0, write 0, timeout 3
    Requests/sec:   2014.45
    Transfer/sec:    267.46KB

And cache is hit. WechatIMG1943

Finally, but still be wary of unexpected mistakes.

joanhey commented 4 years ago

The socket errors happen without opcache too, so I think it is for the 512 concurrent connections in that computer.

The numbers are impressive. What is the code of that test ??

rryqszq4 commented 4 years ago

Very simple code~ and h2 for that.

location = /h1 {
        content_by_php '
                echo "hello, world!"
        ';
}

 location = /h2 {
        content_by_php '
                include "/ngx_php7/t/lib/hello.php";
        ';
}
joanhey commented 4 years ago

And the results of /h1 ??

rryqszq4 commented 4 years ago

No, it's h2

joanhey commented 4 years ago

yes, but I want to compare /h1 vs /h2 (with opcache)

rryqszq4 commented 4 years ago

OK, show you the result at tomorrow.

rryqszq4 commented 4 years ago

@joanhey

  1. Result h1 of use opcache
    ./wrk -H 'Host: 127.0.0.1' -H 'Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7' -H 'Connection: keep-alive' --latency -d 15 -c 512 --timeout 8 -t 28 http://127.0.0.1/h1
    Running 15s test @ http://127.0.0.1/h1
    28 threads and 512 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    66.11ms  355.81ms   6.77s    98.54%
    Req/Sec     1.99k     2.11k   43.31k    84.85%
    Latency Distribution
     50%    2.37ms
     75%    3.31ms
     90%  170.52ms
     99%    1.05s 
    679166 requests in 15.10s, 88.06MB read
    Requests/sec:  44976.38
    Transfer/sec:      5.83MB
  2. Result h1 of not use opcache
    ./wrk -H 'Host: 127.0.0.1' -H 'Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7' -H 'Connection: keep-alive' --latency -d 15 -c 512 --timeout 8 -t 28 http://127.0.0.1/h1
    Running 15s test @ http://127.0.0.1/h1
    28 threads and 512 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    60.00ms  305.88ms   6.77s    98.38%
    Req/Sec     1.84k     1.86k   11.82k    86.27%
    Latency Distribution
     50%    2.32ms
     75%    3.71ms
     90%  167.79ms
     99%  779.61ms
    660201 requests in 15.10s, 85.60MB read
    Socket errors: connect 0, read 0, write 0, timeout 27
    Requests/sec:  43725.02
    Transfer/sec:      5.67MB

    WechatIMG1988

joanhey commented 4 years ago

Could you create a new tag, to tests in the benchmark. And check the results with opcache and the changes in the async mysql.

rryqszq4 commented 4 years ago

Could you create a new tag, to tests in the benchmark. And check the results with opcache and the changes in the async mysql.

OK, I will release the version as soon as possible.

joanhey commented 4 years ago

Now the image with the hello world is not correct.

The php file is almost as fast as inline.

rryqszq4 commented 4 years ago

Sure that the image was already legacy.