When running business on Singapore cloud servers, you often encounter the problem of high worker process usage. This may cause the server to respond slowly or even affect normal access.
On Linux servers, worker processes usually refer to the worker processes of web servers, databases, or application services. When the CPU or memory usage is too high, it may be caused by the following reasons:
1. The server cannot bear the excessive load. The number of website or API requests has increased dramatically and server resources are tight. The high concurrent access worker process is too busy, and too many back-end database queries cause the application processing capacity to decrease.
2. Problems with the code or program itself. There are dead loops in PHP, Python, and Node.js codes, resulting in the process usage not decreasing. Database queries are not optimized, causing the worker process to wait for SQL responses for a long time. The web server configuration is unreasonable, such as too many or too few Nginx processes
3. DDoS attacks or malicious crawlers. There are abnormal IP addresses that frequently request the server, and some crawlers constantly crawl website content, causing the worker process to be continuously busy.
How to accurately locate the Worker process problem? Before optimizing, we need to find out which process causes the server to be overloaded.
Check the CPU and memory usage, and check which processes (usually nginx, php-fpm, node, mysqld) occupy the most resources. Is the CPU fully loaded? More than 80% indicates that the server is under great pressure. Is the load value Load Average too high? Generally, it should be less than 1.5 times the number of CPU cores.
Check the Nginx or Apache process status, and pay attention to whether the Worker process exceeds the set value? Are there a large number of processes in D state (waiting for I/O)?
Check the PHP-FPM process. If the number of PHP-FPM processes is too large, it may be due to a large number of requests or pm.max_children is configured too high.
Find high-load SQL queries. If the database causes problems, you can use mysqladmin. If you see a large number of SELECT ... statements, it may be that some queries are not optimized, causing the database to slow down.
We can also reduce the occupancy by optimizing the Worker process, such as adjusting the Nginx configuration, adjusting the PHP-FPM process pool, and optimizing MySQL queries. If you find that some queries are too slow, you need to optimize the index or rewrite the SQL statement. Prevent malicious requests. If you suspect DDoS or crawler attacks, you can add current limiting in Nginx.
If the server is still overloaded, you can consider upgrading the cloud server configuration (increasing CPU and memory), using CDN cache to reduce the pressure on the source server, and using a distributed architecture (such as Nginx load balancing + multiple PHP-FPM servers).