Answer the question
In order to leave comments, you need to log in
Limit resource consumption of a script
There is a script for parsing data from other sites. All information is entered into an intermediate table.
At the end of parsing, all new records are taken from the intermediate table> 10000 records, and processed in a loop. And entered into the final table.
(processor load)
And at the stage of processing this large number of records, the maximum load on the server occurs, due to which the rest of the sites give a 504 error, and in general the server becomes incapacitated for about 20 minutes until the data processing is completed.
It is necessary to somehow limit the consumption of resources, let it run longer, but do not crash the server.
As a solution, I came up with using usleep () in a loop for the time being, but somehow I'm not satisfied with this option, maybe there is a more correct solution?
Answer the question
In order to leave comments, you need to log in
If the table is in mysql, then it is unlikely, the script itself in this case does not eat the CPU.
Maybe I'm wrong, of course, but have you tried running the script at the lowest priority through nice?
Divide the task into more elementary blocks-stages and process in portions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question