Answer the question
In order to leave comments, you need to log in
How to reduce the load during data processing in a loop?
At the request of the user, I process a large amount of content, in particular images, everything happens in a cycle (async.each). Processing of images consists in cropping and resizing them, then archiving takes place. I have not yet tested this action on loads, but I think the load will not be small.
How can you reduce it? For example, to process an image with some kind of interval, this is the first time I encounter this and my thoughts rest only on setTimeout, will it allow the server to take a break? Or is there something more interesting?
For example, I want to do something like this
async.each(data, function(x, callback) {
setTimeout(function(){
// тут выполняю какие то действия
callback(null);
});
}, function(){
callback(null, data);
});
Answer the question
In order to leave comments, you need to log in
The load cannot be put anywhere, it can only be transferred in time. For example, you have something else being done in parallel and you need at least a little processor - then yes, it makes sense to put Timeout for example 1 second in it, the processor will do its rest and continue to work. Or put everything in a queue and run the task at night when no one notices.
Well, or rewrite the operation with a high load in low-level languages.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question