Having problem with Php fpm

Ok My site is working fine but when the number of visitors increases it breaks suddenly.To find out why it breaks I have been observing the behaviour of my server using the ‘htop’ command.

Using ‘htop’ I noticed that whenever the second value in the figure,

code Tasks 136 , 100 , 2 running

reaches 166 my site breaks,I get something like " 502 Gateway error" .The problem seems to be not coming from RAM because the RAM usage is just 4 to 5 GB but I have 16GB RAM.And also the CPU usage never reaches 100%.So where is the problem coming from? can anyone help me please!

My Server is information:

16GB RAM, 320 GB storage , 6 CPU

My NGinx configuration is :

worker_processes 6;
worker_connections 2000;

My PHP fpm configuration is :

pm = ondemand
pm.max_children = 100
pm.start_servers = 18
pm.min_spare_servers = 9
pm.max_spare_servers = 18
pm.process_idle_timeout = 10s;
pm.max_requests = 500

Am I missing something,I also use WP Super cache!!

Any help will be grateful,thank you in advance.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I had the same issue and solved it by adding a SWAP to my droplet following “How To Add Swap Space on Ubuntu 20.04

It’s happening because your max_connections is being reached. Run these commands and copy/paste the output here:

mv index.html

On the last command, you might need to run it like this:

perl --user root -pass <mysql_root_passwd>

Increase max_children to 150 and restart fpm. Also, check the php-fpm error log. It should have further clues on why it’s failing.