L
L
La2ha2013-02-15 18:11:00
PHP
La2ha, 2013-02-15 18:11:00

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.
image
(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

4 answer(s)
V
Vlad Zhivotnev, 2013-02-15
@La2ha

If the table is in mysql, then it is unlikely, the script itself in this case does not eat the CPU.

S
Stepan, 2013-02-15
@L3n1n

Maybe I'm wrong, of course, but have you tried running the script at the lowest priority through nice?

A
Anton_from_Amber, 2013-02-16
@Anton_from_Amber

Divide the task into more elementary blocks-stages and process in portions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question