bug 770331 - always try and negotiate HTTP Keep-Alive r=biesi
authorPatrick McManus <mcmanus@ducksong.com>
Fri, 20 Jul 2012 08:40:13 -0400
changeset 99906 d3ba16c3c8a09e038d6b8dac264605e4ef0ba31a
parent 99905 3337f0685b75536824e0378eacec031924afa7c8
child 99907 08032fb59ba42fa7b322b810356adec0714771f8
push id12243
push usermcmanus@ducksong.com
push dateFri, 20 Jul 2012 13:42:49 +0000
treeherdermozilla-inbound@18671e974655 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi
bugs770331
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 770331 - always try and negotiate HTTP Keep-Alive r=biesi
b2g/app/b2g.js
mobile/android/app/mobile.js
mobile/xul/app/mobile.js
modules/libpref/src/init/all.js
netwerk/protocol/http/nsHttpConnectionMgr.cpp
netwerk/protocol/http/nsHttpConnectionMgr.h
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
netwerk/test/httpserver/httpd.js
services/sync/tps/extensions/mozmill/resource/stdlib/httpd.js
testing/peptest/peptest/extension/resource/mozmill/stdlib/httpd.js
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -40,17 +40,16 @@ pref("network.protocol-handler.warn-exte
 
 /* http prefs */
 pref("network.http.pipelining", true);
 pref("network.http.pipelining.ssl", true);
 pref("network.http.proxy.pipelining", true);
 pref("network.http.pipelining.maxrequests" , 6);
 pref("network.http.keep-alive.timeout", 600);
 pref("network.http.max-connections", 6);
-pref("network.http.max-connections-per-server", 4);
 pref("network.http.max-persistent-connections-per-server", 4);
 pref("network.http.max-persistent-connections-per-proxy", 4);
 
 // See bug 545869 for details on why these are set the way they are
 pref("network.buffer.cache.count", 24);
 pref("network.buffer.cache.size",  16384);
 
 /* session history */
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -73,17 +73,16 @@ pref("network.protocol-handler.warn-exte
 
 /* http prefs */
 pref("network.http.pipelining", true);
 pref("network.http.pipelining.ssl", true);
 pref("network.http.proxy.pipelining", true);
 pref("network.http.pipelining.maxrequests" , 6);
 pref("network.http.keep-alive.timeout", 600);
 pref("network.http.max-connections", 20);
-pref("network.http.max-connections-per-server", 15);
 pref("network.http.max-persistent-connections-per-server", 6);
 pref("network.http.max-persistent-connections-per-proxy", 8);
 
 // See bug 545869 for details on why these are set the way they are
 pref("network.buffer.cache.count", 24);
 pref("network.buffer.cache.size",  16384);
 
 /* history max results display */
--- a/mobile/xul/app/mobile.js
+++ b/mobile/xul/app/mobile.js
@@ -83,17 +83,16 @@ pref("network.protocol-handler.warn-exte
 
 /* http prefs */
 pref("network.http.pipelining", true);
 pref("network.http.pipelining.ssl", true);
 pref("network.http.proxy.pipelining", true);
 pref("network.http.pipelining.maxrequests" , 6);
 pref("network.http.keep-alive.timeout", 600);
 pref("network.http.max-connections", 6);
-pref("network.http.max-connections-per-server", 4);
 pref("network.http.max-persistent-connections-per-server", 4);
 pref("network.http.max-persistent-connections-per-proxy", 4);
 #ifdef MOZ_PLATFORM_MAEMO
 pref("network.autodial-helper.enabled", true);
 #endif
 
 // See bug 545869 for details on why these are set the way they are
 pref("network.buffer.cache.count", 24);
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -776,42 +776,35 @@ pref("network.http.proxy.version", "1.1"
 
 // enable caching of http documents
 pref("network.http.use-cache", true);
 
 // this preference can be set to override the socket type used for normal
 // HTTP traffic.  an empty value indicates the normal TCP/IP socket type.
 pref("network.http.default-socket-type", "");
 
-pref("network.http.keep-alive", true); // set it to false in case of problems
-pref("network.http.proxy.keep-alive", true);
 // There is a problem with some IIS7 servers that don't close the connection
 // properly after it times out (bug #491541). Default timeout on IIS7 is
 // 120 seconds. We need to reuse or drop the connection within this time.
 // We set the timeout a little shorter to keep a reserve for cases when
 // the packet is lost or delayed on the route.
 pref("network.http.keep-alive.timeout", 115);
 
 // Limit the absolute number of http connections.
 // Note: the socket transport service will clamp the number below 256 if the OS
 // cannot allocate that many FDs, and it also always tries to reserve up to 250
 // file descriptors for things other than sockets.   
 pref("network.http.max-connections", 256);
 
-// limit the absolute number of http connections that can be established per
-// host.  if a http proxy server is enabled, then the "server" is the proxy
-// server.  Otherwise, "server" is the http origin server.
-pref("network.http.max-connections-per-server", 15);
-
-// if network.http.keep-alive is true, and if NOT connecting via a proxy, then
+// If NOT connecting via a proxy, then
 // a new connection will only be attempted if the number of active persistent
 // connections to the server is less then max-persistent-connections-per-server.
 pref("network.http.max-persistent-connections-per-server", 6);
 
-// if network.http.keep-alive is true, and if connecting via a proxy, then a
+// If connecting via a proxy, then a
 // new connection will only be attempted if the number of active persistent
 // connections to the proxy is less then max-persistent-connections-per-proxy.
 pref("network.http.max-persistent-connections-per-proxy", 8);
 
 // amount of time (in seconds) to suspend pending requests, before spawning a
 // new connection, once the limit on the number of persistent connections per
 // host has been reached.  however, a new connection will not be created if
 // max-connections or max-connections-per-server has also been reached.
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -51,18 +51,16 @@ InsertTransactionSorted(nsTArray<nsHttpT
 }
 
 //-----------------------------------------------------------------------------
 
 nsHttpConnectionMgr::nsHttpConnectionMgr()
     : mRef(0)
     , mReentrantMonitor("nsHttpConnectionMgr.mReentrantMonitor")
     , mMaxConns(0)
-    , mMaxConnsPerHost(0)
-    , mMaxConnsPerProxy(0)
     , mMaxPersistConnsPerHost(0)
     , mMaxPersistConnsPerProxy(0)
     , mIsShuttingDown(false)
     , mNumActiveConns(0)
     , mNumIdleConns(0)
     , mTimeOfNextWakeUp(LL_MAXUINT)
     , mReadTimeoutTickArmed(false)
 {
@@ -102,32 +100,28 @@ nsHttpConnectionMgr::EnsureSocketThreadT
 
     mSocketThreadTarget = sts;
 
     return rv;
 }
 
 nsresult
 nsHttpConnectionMgr::Init(PRUint16 maxConns,
-                          PRUint16 maxConnsPerHost,
-                          PRUint16 maxConnsPerProxy,
                           PRUint16 maxPersistConnsPerHost,
                           PRUint16 maxPersistConnsPerProxy,
                           PRUint16 maxRequestDelay,
                           PRUint16 maxPipelinedRequests,
                           PRUint16 maxOptimisticPipelinedRequests)
 {
     LOG(("nsHttpConnectionMgr::Init\n"));
 
     {
         ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
         mMaxConns = maxConns;
-        mMaxConnsPerHost = maxConnsPerHost;
-        mMaxConnsPerProxy = maxConnsPerProxy;
         mMaxPersistConnsPerHost = maxPersistConnsPerHost;
         mMaxPersistConnsPerProxy = maxPersistConnsPerProxy;
         mMaxRequestDelay = maxRequestDelay;
         mMaxPipelinedRequests = maxPipelinedRequests;
         mMaxOptimisticPipelinedRequests = maxOptimisticPipelinedRequests;
 
         mIsShuttingDown = false;
     }
@@ -1104,63 +1098,46 @@ nsHttpConnectionMgr::AtActiveConnectionL
 
     // If there are more active connections than the global limit, then we're
     // done. Purging idle connections won't get us below it.
     if (mNumActiveConns >= mMaxConns) {
         LOG(("  num active conns == max conns\n"));
         return true;
     }
 
-    nsHttpConnection *conn;
-    PRInt32 i, totalCount, persistCount = 0;
-    
-    totalCount = ent->mActiveConns.Length();
-
-    // count the number of persistent connections
-    for (i=0; i<totalCount; ++i) {
-        conn = ent->mActiveConns[i];
-        if (conn->IsKeepAlive()) // XXX make sure this is thread-safe
-            persistCount++;
-    }
+    PRInt32 totalCount = ent->mActiveConns.Length();
 
     // Add in the in-progress tcp connections, we will assume they are
     // keepalive enabled.
     PRUint32 pendingHalfOpens = 0;
-    for (i = 0; i < ent->mHalfOpens.Length(); ++i) {
+    for (PRUint32 i = 0; i < ent->mHalfOpens.Length(); ++i) {
         nsHalfOpenSocket *halfOpen = ent->mHalfOpens[i];
 
         // Exclude half-open's that has already created a usable connection.
         // This prevents the limit being stuck on ipv6 connections that 
         // eventually time out after typical 21 seconds of no ACK+SYN reply.
         if (halfOpen->HasConnected())
             continue;
 
         ++pendingHalfOpens;
     }
     
     totalCount += pendingHalfOpens;
-    persistCount += pendingHalfOpens;
-
-    LOG(("   total=%d, persist=%d\n", totalCount, persistCount));
-
-    PRUint16 maxConns;
+
     PRUint16 maxPersistConns;
 
-    if (ci->UsingHttpProxy() && !ci->UsingConnect()) {
-        maxConns = mMaxConnsPerProxy;
+    if (ci->UsingHttpProxy() && !ci->UsingConnect())
         maxPersistConns = mMaxPersistConnsPerProxy;
-    }
-    else {
-        maxConns = mMaxConnsPerHost;
+    else
         maxPersistConns = mMaxPersistConnsPerHost;
-    }
+
+    LOG(("   connection count = %d, limit %d\n", totalCount, maxPersistConns));
 
     // use >= just to be safe
-    bool result = (totalCount >= maxConns) || ( (caps & NS_HTTP_ALLOW_KEEPALIVE) &&
-                                              (persistCount >= maxPersistConns) );
+    bool result = (totalCount >= maxPersistConns);
     LOG(("  result: %s", result ? "true" : "false"));
     return result;
 }
 
 void
 nsHttpConnectionMgr::ClosePersistentConnections(nsConnectionEntry *ent)
 {
     LOG(("nsHttpConnectionMgr::ClosePersistentConnections [ci=%s]\n",
@@ -2099,22 +2076,16 @@ nsHttpConnectionMgr::OnMsgUpdateParam(PR
 {
     PRUint16 name  = (NS_PTR_TO_INT32(param) & 0xFFFF0000) >> 16;
     PRUint16 value =  NS_PTR_TO_INT32(param) & 0x0000FFFF;
 
     switch (name) {
     case MAX_CONNECTIONS:
         mMaxConns = value;
         break;
-    case MAX_CONNECTIONS_PER_HOST:
-        mMaxConnsPerHost = value;
-        break;
-    case MAX_CONNECTIONS_PER_PROXY:
-        mMaxConnsPerProxy = value;
-        break;
     case MAX_PERSISTENT_CONNECTIONS_PER_HOST:
         mMaxPersistConnsPerHost = value;
         break;
     case MAX_PERSISTENT_CONNECTIONS_PER_PROXY:
         mMaxPersistConnsPerProxy = value;
         break;
     case MAX_REQUEST_DELAY:
         mMaxRequestDelay = value;
--- a/netwerk/protocol/http/nsHttpConnectionMgr.h
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.h
@@ -34,34 +34,30 @@ class nsHttpConnectionMgr : public nsIOb
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 
     // parameter names
     enum nsParamName {
         MAX_CONNECTIONS,
-        MAX_CONNECTIONS_PER_HOST,
-        MAX_CONNECTIONS_PER_PROXY,
         MAX_PERSISTENT_CONNECTIONS_PER_HOST,
         MAX_PERSISTENT_CONNECTIONS_PER_PROXY,
         MAX_REQUEST_DELAY,
         MAX_PIPELINED_REQUESTS,
         MAX_OPTIMISTIC_PIPELINED_REQUESTS
     };
 
     //-------------------------------------------------------------------------
     // NOTE: functions below may only be called on the main thread.
     //-------------------------------------------------------------------------
 
     nsHttpConnectionMgr();
 
     nsresult Init(PRUint16 maxConnections,
-                  PRUint16 maxConnectionsPerHost,
-                  PRUint16 maxConnectionsPerProxy,
                   PRUint16 maxPersistentConnectionsPerHost,
                   PRUint16 maxPersistentConnectionsPerProxy,
                   PRUint16 maxRequestDelay,
                   PRUint16 maxPipelinedRequests,
                   PRUint16 maxOptimisticPipelinedRequests);
     nsresult Shutdown();
 
     //-------------------------------------------------------------------------
@@ -432,18 +428,16 @@ private:
     //-------------------------------------------------------------------------
 
     PRInt32                      mRef;
     mozilla::ReentrantMonitor    mReentrantMonitor;
     nsCOMPtr<nsIEventTarget>     mSocketThreadTarget;
 
     // connection limits
     PRUint16 mMaxConns;
-    PRUint16 mMaxConnsPerHost;
-    PRUint16 mMaxConnsPerProxy;
     PRUint16 mMaxPersistConnsPerHost;
     PRUint16 mMaxPersistConnsPerProxy;
     PRUint16 mMaxRequestDelay; // in seconds
     PRUint16 mMaxPipelinedRequests;
     PRUint16 mMaxOptimisticPipelinedRequests;
     bool mIsShuttingDown;
 
     //-------------------------------------------------------------------------
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -135,17 +135,16 @@ nsHttpHandler::nsHttpHandler()
     , mReferrerLevel(0xff) // by default we always send a referrer
     , mFastFallbackToIPv4(false)
     , mIdleTimeout(PR_SecondsToInterval(10))
     , mSpdyTimeout(PR_SecondsToInterval(180))
     , mMaxRequestAttempts(10)
     , mMaxRequestDelay(10)
     , mIdleSynTimeout(250)
     , mMaxConnections(24)
-    , mMaxConnectionsPerServer(8)
     , mMaxPersistentConnectionsPerServer(2)
     , mMaxPersistentConnectionsPerProxy(4)
     , mMaxPipelinedRequests(32)
     , mMaxOptimisticPipelinedRequests(4)
     , mPipelineAggressive(false)
     , mMaxPipelineObjectSize(300000)
     , mPipelineRescheduleOnTimeout(true)
     , mPipelineRescheduleTimeout(PR_MillisecondsToInterval(1500))
@@ -317,18 +316,16 @@ nsHttpHandler::InitConnectionMgr()
     if (!mConnMgr) {
         mConnMgr = new nsHttpConnectionMgr();
         if (!mConnMgr)
             return NS_ERROR_OUT_OF_MEMORY;
         NS_ADDREF(mConnMgr);
     }
 
     rv = mConnMgr->Init(mMaxConnections,
-                        mMaxConnectionsPerServer,
-                        mMaxConnectionsPerServer,
                         mMaxPersistentConnectionsPerServer,
                         mMaxPersistentConnectionsPerProxy,
                         mMaxRequestDelay,
                         mMaxPipelinedRequests,
                         mMaxOptimisticPipelinedRequests);
     return rv;
 }
 
@@ -796,29 +793,16 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
                                                  (PRUint32)1, MaxSocketCount());
 
             if (mConnMgr)
                 mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS,
                                       mMaxConnections);
         }
     }
 
-    if (PREF_CHANGED(HTTP_PREF("max-connections-per-server"))) {
-        rv = prefs->GetIntPref(HTTP_PREF("max-connections-per-server"), &val);
-        if (NS_SUCCEEDED(rv)) {
-            mMaxConnectionsPerServer = (PRUint8) clamped(val, 1, 0xff);
-            if (mConnMgr) {
-                mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS_PER_HOST,
-                                      mMaxConnectionsPerServer);
-                mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS_PER_PROXY,
-                                      mMaxConnectionsPerServer);
-            }
-        }
-    }
-
     if (PREF_CHANGED(HTTP_PREF("max-persistent-connections-per-server"))) {
         rv = prefs->GetIntPref(HTTP_PREF("max-persistent-connections-per-server"), &val);
         if (NS_SUCCEEDED(rv)) {
             mMaxPersistentConnectionsPerServer = (PRUint8) clamped(val, 1, 0xff);
             if (mConnMgr)
                 mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PERSISTENT_CONNECTIONS_PER_HOST,
                                       mMaxPersistentConnectionsPerServer);
         }
@@ -878,36 +862,16 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
             if (!PL_strcmp(httpVersion, "1.1"))
                 mProxyHttpVersion = NS_HTTP_VERSION_1_1;
             else
                 mProxyHttpVersion = NS_HTTP_VERSION_1_0;
             // it does not make sense to issue a HTTP/0.9 request to a proxy server
         }
     }
 
-    if (PREF_CHANGED(HTTP_PREF("keep-alive"))) {
-        rv = prefs->GetBoolPref(HTTP_PREF("keep-alive"), &cVar);
-        if (NS_SUCCEEDED(rv)) {
-            if (cVar)
-                mCapabilities |= NS_HTTP_ALLOW_KEEPALIVE;
-            else
-                mCapabilities &= ~NS_HTTP_ALLOW_KEEPALIVE;
-        }
-    }
-
-    if (PREF_CHANGED(HTTP_PREF("proxy.keep-alive"))) {
-        rv = prefs->GetBoolPref(HTTP_PREF("proxy.keep-alive"), &cVar);
-        if (NS_SUCCEEDED(rv)) {
-            if (cVar)
-                mProxyCapabilities |= NS_HTTP_ALLOW_KEEPALIVE;
-            else
-                mProxyCapabilities &= ~NS_HTTP_ALLOW_KEEPALIVE;
-        }
-    }
-
     if (PREF_CHANGED(HTTP_PREF("pipelining"))) {
         rv = prefs->GetBoolPref(HTTP_PREF("pipelining"), &cVar);
         if (NS_SUCCEEDED(rv)) {
             if (cVar)
                 mCapabilities |=  NS_HTTP_ALLOW_PIPELINING;
             else
                 mCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
         }
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -281,17 +281,16 @@ private:
     PRIntervalTime mIdleTimeout;
     PRIntervalTime mSpdyTimeout;
 
     PRUint16 mMaxRequestAttempts;
     PRUint16 mMaxRequestDelay;
     PRUint16 mIdleSynTimeout;
 
     PRUint16 mMaxConnections;
-    PRUint8  mMaxConnectionsPerServer;
     PRUint8  mMaxPersistentConnectionsPerServer;
     PRUint8  mMaxPersistentConnectionsPerProxy;
     PRUint16 mMaxPipelinedRequests;
     PRUint16 mMaxOptimisticPipelinedRequests;
     bool     mPipelineAggressive;
     PRInt64  mMaxPipelineObjectSize;
     bool     mPipelineRescheduleOnTimeout;
     PRIntervalTime mPipelineRescheduleTimeout;
--- a/netwerk/test/httpserver/httpd.js
+++ b/netwerk/test/httpserver/httpd.js
@@ -508,22 +508,22 @@ nsHttpServer.prototype =
       throw Cr.NS_ERROR_ALREADY_INITIALIZED;
 
     this._port = port;
     this._doQuit = this._socketClosed = false;
 
     this._host = host;
 
     // The listen queue needs to be long enough to handle
-    // network.http.max-connections-per-server concurrent connections,
+    // network.http.max-persistent-connections-per-server concurrent connections,
     // plus a safety margin in case some other process is talking to
     // the server as well.
     var prefs = getRootPrefBranch();
     var maxConnections =
-      prefs.getIntPref("network.http.max-connections-per-server") + 5;
+      prefs.getIntPref("network.http.max-persistent-connections-per-server") + 5;
 
     try
     {
       var loopback = true;
       if (this._host != "127.0.0.1" && this._host != "localhost") {
         var loopback = false;
       }
 
--- a/services/sync/tps/extensions/mozmill/resource/stdlib/httpd.js
+++ b/services/sync/tps/extensions/mozmill/resource/stdlib/httpd.js
@@ -488,22 +488,22 @@ nsHttpServer.prototype =
       throw Cr.NS_ERROR_ALREADY_INITIALIZED;
 
     this._port = port;
     this._doQuit = this._socketClosed = false;
 
     this._host = host;
 
     // The listen queue needs to be long enough to handle
-    // network.http.max-connections-per-server concurrent connections,
+    // network.http.max-persistent-connections-per-server concurrent connections,
     // plus a safety margin in case some other process is talking to
     // the server as well.
     var prefs = getRootPrefBranch();
     var maxConnections =
-      prefs.getIntPref("network.http.max-connections-per-server") + 5;
+      prefs.getIntPref("network.http.max-persistent-connections-per-server") + 5;
 
     try
     {
       var loopback = true;
       if (this._host != "127.0.0.1" && this._host != "localhost") {
         var loopback = false;
       }
 
--- a/testing/peptest/peptest/extension/resource/mozmill/stdlib/httpd.js
+++ b/testing/peptest/peptest/extension/resource/mozmill/stdlib/httpd.js
@@ -488,22 +488,22 @@ nsHttpServer.prototype =
       throw Cr.NS_ERROR_ALREADY_INITIALIZED;
 
     this._port = port;
     this._doQuit = this._socketClosed = false;
 
     this._host = host;
 
     // The listen queue needs to be long enough to handle
-    // network.http.max-connections-per-server concurrent connections,
+    // network.http.max-persistent-connections-per-server concurrent connections,
     // plus a safety margin in case some other process is talking to
     // the server as well.
     var prefs = getRootPrefBranch();
     var maxConnections =
-      prefs.getIntPref("network.http.max-connections-per-server") + 5;
+      prefs.getIntPref("network.http.max-persistent-connections-per-server") + 5;
 
     try
     {
       var loopback = true;
       if (this._host != "127.0.0.1" && this._host != "localhost") {
         var loopback = false;
       }