0

I'm altering a huge db table, disk utilization raises up to 90-100%.

Static content is being served fast as usual by NGINX, but PHP pages are loading for 10-20 seconds instead of a usual 0.2 seconds.

I have

echo 'Generated in ' . microtime( true ) - $start . ' sec.';

at the end of every page and it shows that the page was generated in 0.1 seconds, while its loading took 10+ seconds:

Request sent    0.22 ms
Waiting (TTFB)  12.84 s
Content Download    59.33 ms

Average page size is 30-40 kb, and NGINX buffers are:

fastcgi_buffers 32 32k;
fastcgi_buffer_size 64k;

So NGINX shouldn't use disk to serve the page.

Why could this happen? Is there some NGINX or PHP-FPM settings that forced them to use disk instead of keeping data in memory?

eugene99
  • 1
  • 1
  • You are running altering db on the same server, yes? This buffers are used to hold first part of http response which are *headers*. Check this: https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes – Sebastian Tkaczyk Aug 28 '17 at 08:53
  • Yes. As far as I understand fastcgi_buffer_size is for headers and fastcgi_buffers is for the rest of the response. Isn't it right? – eugene99 Aug 28 '17 at 09:45
  • @eguene99 I think that you are confusing this with some type of cacheing responses. – Sebastian Tkaczyk Aug 28 '17 at 13:17

1 Answers1

0

If you want to store faster your generated responses you should think about some sort of cache. It's a big topic in webdev and it's nicely explained (for nginx) here:

https://www.nginx.com/blog/nginx-caching-guide/

Remember about setting cache HTTP headers like max-age, cache-control in your responses. Read about headers here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control