简体   繁体   English

使用异步js llin进行异步并行调用

[英]async parallel calls using async js llin

arrayOfFunctions is an array with 1000+ functions in it. arrayOfFunctions是一个包含1000多个函数的数组。 Each function is making an async call to AWS S3 to get an object's metadata. 每个函数都对AWS S3进行异步调用以获取对象的元数据。

Function: 功能:

function (cb) {$.when(getMetadata("bucketname","objectkey"))
                    .done(function (data) {
                        cb(null, data)
                    });

For a single function, it takes less than a second to read the metadata, if I execute 1000s of them one by one that will take 1 second per function. 对于单个功能,如果我逐个执行1000个元数据,则每个元数据需要不到一秒钟的时间来读取元数据。

How I call with async.parallel: 我如何用async.parallel调用:

    async.parallel(arrayOfFunctions, function (err, result) {
            console.log(result);
        }
    });

If I use async.parallel, does it mean that all the functions are executed at once and parallelly? 如果我使用async.parallel,是否意味着所有功能都同时并行执行? should I get results of all of them at once and just 1-2 seconds? 我应该在1-2秒内一次获得所有结果吗?

thanks 谢谢

Not quite. 不完全的。 There's a limit on how many connections you can open at the same time. 可以同时打开的连接数是有限制的。 For example the web browsers place a limit on this, each browser having a different limit. 例如,Web浏览器对此设置了限制,每个浏览器都有不同的限制。

Usually, with a small # of tasks, you wouldn't hit this limit and perceive. 通常,只需执行少量任务,您就不会达到此极限并无法感知。 But having 1000s of tasks trying to fetch from AWS you probably won't be having the 1-2s execution time you are expecting. 但是,如果有数千个任务试图从AWS提取,您可能将不会有您期望的1-2s执行时间。

Consider also the bandwidth limit of trying to download 1000s of images at the same time, how fast your server's internet connection would have to be to download it all in 1-2s? 还考虑尝试同时下载1000张图像的带宽限制,您的服务器的Internet连接必须以多快的速度在1-2s内下载所有图像,这又有多大限制?

For further reference see this stackoverflow discussion 有关更多参考,请参见此stackoverflow讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM