浏览器对同一个Server并发连接数限制
HTTP/1.1协议的RFC2616中8.1.4中讲到:
Clients that use persistent connections SHOULD limit the number of simultaneous connections that they maintain to a given server. A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users. These guidelines are intended to improve HTTP response times and avoid congestion.
使用持久连接的Client不应该维持到同一Server多于2个的连接数,基本上,各个浏览器都依据该规范,实现了自己的限制,如下,引自这里:
- Browser HTTP/1.1 HTTP/1.0
- IE 6,7 2 4
- IE 8 6 6
- Firefox 2 2 8
- Firefox 3 6 6
- Safari 3,4 4 4
- Chrome 1,2 6 ?
- Chrome 3 4 4
- Opera 4 4
最杯具的莫过于IE6了,严格按照RFC规范来实现,每Server只能并发2个连接,到了IE8就有了改进,增大到了6个,见这里
这个限制,对于普通的Web应用来讲,影响不算太大,毕竟正常的连接请求都会很快有返回结果的
但如果在Web中要是用长连接的话,就可能会有比较大的问题了,尤其是在IE6里面
长连接会一直占用一个连接数,如果你有2个长连接,那就更杯具了,浏览器这时将无法向同这个Server去request了...
解决办法,看起来只有2个:
1. 修改浏览器的设置,IE和Firefox貌似都可以设置,但我们的Web应用总不能要求所有的用户都去修改那个设置吧
2. 把长连接的请求分发到其它的Server上,不要和普通的请求放在同一个Domain下面,但这样ajax就会有跨域的问题了,也许可以试试Jsonp?