Server has no load but slow nginx responses

I am having an issue with nginx webserver and can’t figure out why its happening.

I had setup a droplet with nginx + php7.4-fpm. i noticed the server has approximately 30% load but the nginx responses are taking more than 4seconds to return a response.

The server has to process 80 request/second. After setup the response time took 100ms to return a response with no load, but with load it took more than 4 seconds.

Already tried with 2 worker process (as the server has 2vCPU and 8gb ram) and 512 connection each.

Can anyone give any solution?

2 thoughts on “Server has no load but slow nginx responses”

  1. It sounds likely that whatever php is executing, is not doing so quickly. Set up a new [custom logging format](https://nginx.org/en/docs/http/ngx_http_log_module.html#log_format) which has these additional values:

    * $upstream\_response\_time
    * $upstream\_addr
    * $upstream\_status

    This will confirm that when you proxy to php, things are slow, and not that nginx itself is slow. There are several things you can do to help alleviate that. You can set up a response cache in nginx (see: [fastcgi_cache if you’re proxying with fastcgi_pass](https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache)), but make sure the content you’re caching should be cached, and that you have the cache key set correctly.

    For PHP, since 5.5 opcache has been available and I believe enabled by default. Check out the docs and make sure that your installation is using opcaching properly: https://www.php.net/manual/en/book.opcache.php

    Once you’ve run down those paths, and determined that whatever you’re running on php is slow and not nginx itself, start googling for optimization guides.

    Reply
  2. >The server has to process 80 request/second

    Increase the worker process count to at least 10.

    What are your php-fpm pool process limits at? I recommend pm=dynamic pm.max_children=50

    Reply

Leave a Comment