在什么情况下我的浏览器尝试重复使用多个请求的TCP连接? [英] Under what circumstances will my browser attempt to re-use a TCP connection for multiple requests?

查看:1168
本文介绍了在什么情况下我的浏览器尝试重复使用多个请求的TCP连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Firefox,但我想知道如何浏览器一般决定这。

I am using Firefox, but I'd like to know how browsers decide this in general.

看来,当我两次访问相同的URL在短时间内,我的浏览器尝试重新使用这两个请求的TCP相同的连接(这就是所谓的保活)。然而,当我访问两个不同的URL(但仍然由同一台服务器提供),浏览器的有时决定开辟为每个请求一个新的连接。显然,浏览器不使用单连接每个URL策略。

It seems that when I access the same URL twice in a short amount of time, my browser tries to re-use the TCP same connection for both requests (this is called keep-alive). However, when I access two different URLs (but still served by the same server), the browser sometimes decides to open up a new connection for each request. Obviously, the browser does not use a one-connection-per-URL policy.

我问这个,因为我想实现使用长轮询的Web服务。我可以想像,一个用户可能想打开多个标签这种服务在同一个浏览器。然而,保活,第二长轮询请求不会发送,直到第一个完成了(至少在Firefox),因为该浏览器尝试他们两人推到同一个插座,我没有当我想到设计该服务。即使浏览器实现了管内衬,没有办法,我可以在我的第一个响应第二个请求作出回应,因为HTTP任务,我才能完成的响应。

I am asking this because I am trying to implement a web service that uses long polling. I can imagine that a user might want to open this service in multiple tabs on the same browser. However, with keep-alive, the second long poll request does not get sent until the first one completes (at least in Firefox), because the browser is trying to shove both of them into the same socket, which I did not expect when I designed the service. Even if the browser implements pipe-lining, there is no way that I can respond to the second request before I respond to the first, because HTTP mandates that I complete the responses in order.

推荐答案

在使用HTTP / 1.1,默认情况下,TCP连接处于打开状态重用。这是不是开始要求每一个新的连接更好的性能。连接可重复使用的<​​strong>但的连接可以通过任何一方在任何时候关闭。

When using HTTP/1.1, by default, the TCP connections are left open for reuse. This is for better performance than starting a new connection per request. The connection can be reused but the connection could close at any time by any of the parties.

您应该阅读 HTTP1.1 和永久连接的部分。

You should read HTTP1.1 and the part on persistent connections.

在你的情况下,它甚至没有使用HTTP流水线(不广泛支持),因为下一个请求的第一个响应后发送

In your case it is not even using HTTP pipelining (not broadly supported) because the next request is sent after the response of the first.

该浏览器有一个连接池,然后重新使用每个主机名。一般来说,浏览器不应该重复使用多个主机名的单一连接,即使这些主机名解析居然向同一个IP地址。

The browsers have a connection pool and reuse it per hostname. Generally speaking, a browser should not reuse a single connection for multiple hostnames, even if those hostnames actually resolve to the same IP address.

大多数浏览器允许用户配置或覆盖每台服务器的持久连接数;大部分现代浏览器默认为六人。如果Firefox是的真正的阻止第二个请求,因为已经有活跃的连接,这是在Firefox中的错误,并应在其bug跟踪系统提交。但是,如果这样的漏洞存在,我想你会看到很多网站坏了。

Most browsers allow the user to configure or override the number of persistent connections per server; most modern browsers default to six. If Firefox is truly blocking the second request because there's already a connection active, this is a bug in Firefox and should be filed in their bug tracking system. But if such a bug existed, I think you'd see many sites broken.

这篇关于在什么情况下我的浏览器尝试重复使用多个请求的TCP连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆