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
643 stars 55 forks source link

Memory consumption #97

Closed joanhey closed 4 years ago

joanhey commented 4 years ago

Hi

Excessive memory consuption

After updating the Dstats of the benchmark, php-ngx is consuming excessive memory. We need to find where is that problem. Because also affect the performance surely. The servers in Citrine have 32 Gb memory, and php-ngx is using it near to the limit.

Platform Memory in Mb
Php-ngx-mysql 32.422
Php-ngx-psql 27.235
Php-ngx-async 12.500
Openresty 2.217
Workerman-pgsql 1.112

https://ajdust.github.io/tfbvis/

Performance

When I tried to use 4x workers per cpu core in php-ngx-pgsql, like we do with Workerman, go and others, php-ngx was unable to start and send this error:

https://tfb-status.techempower.com/unzip/results.2020-02-29-11-51-37-279.zip/results/20200225182242/php-ngx-pgsql/run/php-ngx-pgsql.log

At first I didn't know where was the problem, but now it's clear that is using more memory than the server have.

But php-ngx is performing magnificently :) and still can grow much more in performance.

Thank you

rryqszq4 commented 4 years ago

@joanhey Thanks report, today i did some tests including the same php, nginx, os versions, but no memory leaks were found.

The ngx_php memory limit of 128M per worker process by default. If the memory is overload, it will be printed in error.log, but not.

At present, we still donot know nothing about this problem. I will add some memory monitoring logs later.

joanhey commented 4 years ago

After some tests, the problem is NOT in php-ngx.

The problem is in the nginx.conf, that it has a too aggressive configuration. Especially in the number of worker_connections. That don't affect an nginx alone, but also is not faster with that high number. But affect if it have any embedded language in nginx.

I will investigate a little more and try to explain de results later.

joanhey commented 4 years ago

Nginx create worker_connections at start, not dynamically. The last nginx.conf has an overly aggressive in the number of worker_connections.

Now it's changed and use 4x workers per cpu core. And use a lot less memory and it's faster.

https://www.techempower.com/benchmarks/#section=test&runid=c7152e8f-5b33-4ae7-9e89-630af44bc8de&hw=ph&test=fortune

Php-ngx scale really good :) to the maximum 512 concurrent connections. And I think that will be more performant with more concurrent sessions.

PD: The 3 before php-ngx: lithium-postgres, hyper-db and atreugo-prefork-quicktemplate had the maximum req/s with 256 concurrent sessions and degrade the req/s with 512, contrary to php-ngx.

Good joob @rryqszq4 !!!

rryqszq4 commented 4 years ago

@joanhey Thanks feedback, great~