``Promise.ly)遭受浏览器施加的并发连接的极限吗?
假设API服务器正在使用HTTP/1.1,并且浏览器的限制为每个域的6并发TCP连接。 这是否意味着如果我一次使用Promise.All
一次进行7个API调用,那么最后一个api
将必须等待第一个api
'要求返回网络?
Promise.all([api(), api(), api(), api(), api(), api(), api()]) // 7 api calls
HTTP/2是否也可以通过多路复用来解决此问题。所有这些API调用都将在同一连接上,因此他们不需要等待任何东西?
Assume an api server is using HTTP/1.1 and the browser has a limit of 6 concurrent TCP connections per domain.
Does that mean if I do 7 api calls at once with Promise.all
then the last api
will have to wait for the first api
's request to come back over the network?
Promise.all([api(), api(), api(), api(), api(), api(), api()]) // 7 api calls
Also does HTTP/2 solve this problem with multiplexing where all the these API calls will be on the same connection so they don't need to wait for anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,确实如此。
您的
Promise.All([API(),API(),...])
语句将立即运行所有api()
函数调用。这将导致前6个请求被发送,并且第7请求将排队,直到前6个完成之一,在这种情况下,浏览器将发送第七。这种行为实际上与
Promise.all()
没有任何关系。如果您只是这样做的话,也会发生相同的行为:即使仅使用该声明,第七http请求才能发送到主机,直到前6个完成之一。这完全是因为浏览器的连接限制了同一主机。
仅供参考,
Promise.all()
仍然可以使用,并且所有API请求仍然可以正常工作,只需等待所有请求即可完成的更长的时间,而不是您没有达到连接极限。Yes, it does.
Your
Promise.all([api(), api(), ...])
statement will immediately run allapi()
function calls. That will cause the first 6 requests to get sent and the 7th will be queued until one of the first 6 finishes in which case the browser will the send the 7th.This behavior doesn't actually have anything to do with
Promise.all()
. The same behavior would occur if you just did this:Even with just that statement, the 7th http request wouldn't get sent to the host until one of the first 6 had completed. It's entirely because of the browser's connection limits to the same host.
FYI, the
Promise.all()
will still work and all the api requests will still work, it will just have to wait a bit longer for all requests to complete than if you weren't hitting the connection limits.是的,但这不是
Promise.all
的限制。通常,操作一样,等同于
像在结果传递之前对参数列表中的所有 在参数列表中进行所有表达式。如果评估所有内容的过程都会引起一系列API调用,则其他功能 -
Promise.all
或enternfn
不可能做任何事情,因为这些函数发生在功能运行之前发生。如果我们可以假设限制如您所说的 - 浏览器仅限于与API的6个连接,那么是的。
是的,HTTP/2在这种情况下有很大帮助,因为它们每个域只需要一个连接,并且可以在该连接上发送多个请求,而无需遇到浏览器连接限制。
Yes, but this isn't a limitation particular to
Promise.all
. In general, an expression likeis equivalent to doing
Everything inside the argument list gets evaluated before the result is passed. If the process of evaluating everything makes a bunch of API calls, the other function -
Promise.all
oranotherFn
cannot possibly do anything about that, because those occur before the function runs.If we can assume that the restrictions are as you've said - the browser is limited to 6 connections to the API at once - then yes.
Yes, HTTP/2 is of great help in these sorts of situations, because they need only one connection per domain, and can send multiple requests over that connection, without running into the browser connection limit.