天天看點

浏覽器并發連接配接數(轉載)

這是個老話題了,先總結一下HTTP1.1下主流浏覽器在單個主機下的并發連接配接數:

IE6                                      2

IE7                                      2

IE8                                      6

Firefox2                               2

Firefox3                               6

Safari 3,4                      4     

Chrome 1,2                    6     

Opera 9.63,10.00alpha     4 

看上去巧合的是:老版本的IE和Firefox都使用較低的單個主機并發連接配接數(2),而新版本的IE和Firefox都使用較高的單個主機并發連接配接數(6)。說起來老版本的IE和Firefox之是以采用較低的單個主機并發連接配接數是有道理的,在RFC2616裡明确要求了單個主機并發連接配接數的數目:

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.

不過标準總會落後于現實。在當今的網絡環境裡再使用較低的單個主機并發連接配接數已經越來越顯得不合時宜了,是以說新版本的IE和Firefox才會不約而同的采用較高的單個主機并發連接配接數。

不過很多時候我們為了效率還想得到更高的并發連接配接數,比如說我們總會看到一些大網站采用獨立域名或者二級域名來設定專門的圖檔伺服器,其實有一部分原因就 是為了增加并發連接配接數。至于使用獨立域名還是二級域名的差别在于Cookie的影響,當使用和主站根域名相同的二級域名時,請求的同時也會捎帶着傳遞主站 根域名的Cookie,而使用和主站根域名不同的獨立域名時,則不會受主站根域名Cookie的影響,是以帶寬占用會更小一些。

不過也不是說并發連接配接數越大越好,假如新版浏覽器得到普及,即使你的網站的平均流量還維持在和以前一樣的水準,那麼峰值流量也會成倍增加。

順便說說Firefox下怎麼調整單個主機下的并發數:

# about:config

network.http.max-connections                      : 30

network.http.max-connections-per-server           : 15

network.http.max-persistent-connections-per-proxy : 8

network.http.max-persistent-connections-per-server: 6

需要說明的是HTTP1.1下以network.http.max-persistent-connections-per-server的指為準,這是 因為HTTP1.1下預設都是持久連接配接,反之如果是HTTP1.0,則以network.http.max-connections-per- server為準。

如果你使用TamperData檢測一下,就能發現:

HTTP1.1下Connection: Keep-Alive

HTTP1.0下Connection: Close

一個測試并發速度的頁面:

http://stevesouders.com/hpws/parallel-downloads.php

參考連結:Roundup on Parallel Connections

http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/

轉載于:http://blog.chinaunix.net/u2/61187/showart_1983685.html

轉載于:https://www.cnblogs.com/flyingchen/archive/2009/09/03/1559945.html

php