bug 770331 - always try and negotiate HTTP Keep-Alive r=biesi

--HG--
extra : rebase_source : d348e3ec56faa48fbed5c4f0f697dee6658e21b2
This commit is contained in:
Patrick McManus 2012-07-20 08:40:13 -04:00
parent 2e6fb8937e
commit 5b9ce7432a
11 changed files with 15 additions and 97 deletions

View File

@ -45,7 +45,6 @@ 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);

View File

@ -78,7 +78,6 @@ 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);

View File

@ -88,7 +88,6 @@ 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

View File

@ -781,8 +781,6 @@ pref("network.http.use-cache", true);
// 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.
@ -796,17 +794,12 @@ pref("network.http.keep-alive.timeout", 115);
// 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);

View File

@ -56,8 +56,6 @@ nsHttpConnectionMgr::nsHttpConnectionMgr()
: mRef(0)
, mReentrantMonitor("nsHttpConnectionMgr.mReentrantMonitor")
, mMaxConns(0)
, mMaxConnsPerHost(0)
, mMaxConnsPerProxy(0)
, mMaxPersistConnsPerHost(0)
, mMaxPersistConnsPerProxy(0)
, mIsShuttingDown(false)
@ -107,8 +105,6 @@ nsHttpConnectionMgr::EnsureSocketThreadTargetIfOnline()
nsresult
nsHttpConnectionMgr::Init(PRUint16 maxConns,
PRUint16 maxConnsPerHost,
PRUint16 maxConnsPerProxy,
PRUint16 maxPersistConnsPerHost,
PRUint16 maxPersistConnsPerProxy,
PRUint16 maxRequestDelay,
@ -121,8 +117,6 @@ nsHttpConnectionMgr::Init(PRUint16 maxConns,
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
mMaxConns = maxConns;
mMaxConnsPerHost = maxConnsPerHost;
mMaxConnsPerProxy = maxConnsPerProxy;
mMaxPersistConnsPerHost = maxPersistConnsPerHost;
mMaxPersistConnsPerProxy = maxPersistConnsPerProxy;
mMaxRequestDelay = maxRequestDelay;
@ -1109,22 +1103,12 @@ nsHttpConnectionMgr::AtActiveConnectionLimit(nsConnectionEntry *ent, PRUint8 cap
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.
@ -1137,25 +1121,18 @@ nsHttpConnectionMgr::AtActiveConnectionLimit(nsConnectionEntry *ent, PRUint8 cap
}
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;
}
@ -2104,12 +2081,6 @@ nsHttpConnectionMgr::OnMsgUpdateParam(PRInt32, void *param)
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;

View File

@ -39,8 +39,6 @@ public:
// 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,
@ -55,8 +53,6 @@ public:
nsHttpConnectionMgr();
nsresult Init(PRUint16 maxConnections,
PRUint16 maxConnectionsPerHost,
PRUint16 maxConnectionsPerProxy,
PRUint16 maxPersistentConnectionsPerHost,
PRUint16 maxPersistentConnectionsPerProxy,
PRUint16 maxRequestDelay,
@ -437,8 +433,6 @@ private:
// connection limits
PRUint16 mMaxConns;
PRUint16 mMaxConnsPerHost;
PRUint16 mMaxConnsPerProxy;
PRUint16 mMaxPersistConnsPerHost;
PRUint16 mMaxPersistConnsPerProxy;
PRUint16 mMaxRequestDelay; // in seconds

View File

@ -140,7 +140,6 @@ nsHttpHandler::nsHttpHandler()
, mMaxRequestDelay(10)
, mIdleSynTimeout(250)
, mMaxConnections(24)
, mMaxConnectionsPerServer(8)
, mMaxPersistentConnectionsPerServer(2)
, mMaxPersistentConnectionsPerProxy(4)
, mMaxPipelinedRequests(32)
@ -322,8 +321,6 @@ nsHttpHandler::InitConnectionMgr()
}
rv = mConnMgr->Init(mMaxConnections,
mMaxConnectionsPerServer,
mMaxConnectionsPerServer,
mMaxPersistentConnectionsPerServer,
mMaxPersistentConnectionsPerProxy,
mMaxRequestDelay,
@ -801,19 +798,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
}
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)) {
@ -883,26 +867,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
}
}
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)) {

View File

@ -286,7 +286,6 @@ private:
PRUint16 mIdleSynTimeout;
PRUint16 mMaxConnections;
PRUint8 mMaxConnectionsPerServer;
PRUint8 mMaxPersistentConnectionsPerServer;
PRUint8 mMaxPersistentConnectionsPerProxy;
PRUint16 mMaxPipelinedRequests;

View File

@ -513,12 +513,12 @@ nsHttpServer.prototype =
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
{

View File

@ -493,12 +493,12 @@ nsHttpServer.prototype =
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
{

View File

@ -493,12 +493,12 @@ nsHttpServer.prototype =
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
{