my codes transfers huge number of files from one cloud storage to another cloud storage (same region). The workflow is downloading the source file stream, then uploading the stream to the target storage.
If running them in a non-promise loop, the transferring is fast(say, 100M/s), but will hit the memory limit. Finally the server crashes.
if in a promise chain, i.e. run the next job after the last job completes, the crash problem is solved, but the transferring speed is very slow (say 10M/s).
My question: why the promise would affect the downloading & uploading speed? or anything I missed?
code snippet:
transferArray.forEach(function (eachTransfer) {
queue = queue.then(function(result){
// put result somewhere
return eachFileTransfer(jobId,userid,eachTransfer);
});
});
queue.then(function(){
console.log('done');
});
I am thinking to use PromisePool with concurrences, but not sure how much the speed would be improved, and the reasonable number of concurrences I should set. the ref post: Execute promises concurrently with a buffer pool size in Javascript