slowly, skipping seconds script sends a massive number of updates to the database
RM99-825 MYR
En curso
Publicado hace más de 8 años
RM99-825 MYR
Pagado a la entrega
The site was responding slowly and skipping seconds because the script public_html/[login to view URL], which runs every 5 minutes, sends a massive number of updates to the database in an unrestrained while loop. This causes MySQL to consume a huge amount of disk IO, however the script is pushing the queries faster than MySQL can write tot he disk. This causes one of the CPU cores to be fully consumed by disk IO, and no disk IO available to anything else. This causes load to increase, and everything else on the server to begin to run slowly.
I backed that script up, and put a 150000 microsecond delay in between database updates, on line 133. This still allows for it to function fairly quickly, but without trashing the disk and spiking load on the server on its own.
I also noticed that that script has no replication control. It should be modified check if it is already running, and to only run if it is not running. The cron runs the script every 5 minutes, but it may take longer for 5 minutes for the script to complete. This causes multiple copies of it to be running at the same time, as new ones are spawned before the old ones finish. When there are multiple copies of this running simultaneously, it overloads MySQL with too many updates, and again causes the issue.
I've changed the IO scheduler to one which should allow more IO to other processes. This and putting the light sleep in the script is allowing the server to remain fairly responsive, and the site is loading quickly at this time. I would highly recommend implementing some logic in the script to prevent it from running more than one instance, and possibly even reducing the cron frequency of it