Bug 1037184 - Extended the speculative connection overrider to track predictor preconnects. r=hurley

This commit is contained in:
Jeremy Poulin 2014-07-14 11:30:18 -07:00
parent 8712497a35
commit 6240993aa3
5 changed files with 71 additions and 4 deletions

View File

@ -35,7 +35,7 @@ interface nsISpeculativeConnect : nsISupports
* inline) to determine whether or not to actually make a speculative
* connection.
*/
[builtinclass, uuid(2b6d6fb6-ab28-4f4c-af84-bfdbb7866d72)]
[builtinclass, uuid(a9cdd875-2ef8-4d53-95d6-e4e18f65e0db)]
interface nsISpeculativeConnectionOverrider : nsISupports
{
/**
@ -57,4 +57,10 @@ interface nsISpeculativeConnectionOverrider : nsISupports
* connection.
*/
[infallible] readonly attribute boolean ignoreIdle;
/*
* Used by the Predictor to gather telemetry data on speculative connection
* usage.
*/
[infallible] readonly attribute boolean isFromPredictor;
};

View File

@ -388,6 +388,13 @@ Predictor::GetParallelSpeculativeConnectLimit(
return NS_OK;
}
NS_IMETHODIMP
Predictor::GetIsFromPredictor(bool *isFromPredictor)
{
*isFromPredictor = true;
return NS_OK;
}
// Predictor::nsIInterfaceRequestor
NS_IMETHODIMP

View File

@ -359,6 +359,7 @@ public: // intentional!
uint32_t mParallelSpeculativeConnectLimit;
bool mIgnoreIdle;
bool mIgnorePossibleSpdyConnections;
bool mIsFromPredictor;
// As above, added manually so we can use nsRefPtr without inheriting from
// nsISupports
@ -407,6 +408,7 @@ nsHttpConnectionMgr::SpeculativeConnect(nsHttpConnectionInfo *ci,
overrider->GetIgnoreIdle(&args->mIgnoreIdle);
overrider->GetIgnorePossibleSpdyConnections(
&args->mIgnorePossibleSpdyConnections);
overrider->GetIsFromPredictor(&args->mIsFromPredictor);
}
nsresult rv =
@ -1401,6 +1403,11 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_USED_SPECULATIVE_CONN> usedSpeculativeConn;
++usedSpeculativeConn;
if (ent->mHalfOpens[i]->IsFromPredictor()) {
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_USED> totalPreconnectsUsed;
++totalPreconnectsUsed;
}
// return OK because we have essentially opened a new connection
// by converting a speculative half-open to general use
return NS_OK;
@ -2061,7 +2068,8 @@ nsresult
nsHttpConnectionMgr::CreateTransport(nsConnectionEntry *ent,
nsAHttpTransaction *trans,
uint32_t caps,
bool speculative)
bool speculative,
bool isFromPredictor)
{
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
@ -2070,6 +2078,12 @@ nsHttpConnectionMgr::CreateTransport(nsConnectionEntry *ent,
sock->SetSpeculative(true);
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn;
++totalSpeculativeConn;
if (isFromPredictor) {
sock->SetIsFromPredictor(true);
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated;
++totalPreconnectsCreated;
}
}
nsresult rv = sock->SetupPrimaryStreams();
@ -2785,11 +2799,13 @@ nsHttpConnectionMgr::OnMsgSpeculativeConnect(int32_t, void *param)
gHttpHandler->ParallelSpeculativeConnectLimit();
bool ignorePossibleSpdyConnections = false;
bool ignoreIdle = false;
bool isFromPredictor = false;
if (args->mOverridesOK) {
parallelSpeculativeConnectLimit = args->mParallelSpeculativeConnectLimit;
ignorePossibleSpdyConnections = args->mIgnorePossibleSpdyConnections;
ignoreIdle = args->mIgnoreIdle;
isFromPredictor = args->mIsFromPredictor;
}
if (mNumHalfOpenConns < parallelSpeculativeConnectLimit &&
@ -2797,7 +2813,7 @@ nsHttpConnectionMgr::OnMsgSpeculativeConnect(int32_t, void *param)
!ent->mIdleConns.Length()) &&
!RestrictConnections(ent, ignorePossibleSpdyConnections) &&
!AtActiveConnectionLimit(ent, args->mTrans->Caps())) {
CreateTransport(ent, args->mTrans, args->mTrans->Caps(), true);
CreateTransport(ent, args->mTrans, args->mTrans->Caps(), true, isFromPredictor);
}
else {
LOG((" Transport not created due to existing connection count\n"));
@ -2846,6 +2862,7 @@ nsHalfOpenSocket::nsHalfOpenSocket(nsConnectionEntry *ent,
, mTransaction(trans)
, mCaps(caps)
, mSpeculative(false)
, mIsFromPredictor(false)
, mHasConnected(false)
, mPrimaryConnectedOK(false)
, mBackupConnectedOK(false)
@ -3716,6 +3733,11 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
if (halfOpen->IsSpeculative()) {
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN> unusedSpeculativeConn;
++unusedSpeculativeConn;
if (halfOpen->IsFromPredictor()) {
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_UNUSED> totalPreconnectsUnused;
++totalPreconnectsUnused;
}
}
// A failure to create the transport object at all

View File

@ -451,6 +451,9 @@ private:
bool IsSpeculative() { return mSpeculative; }
void SetSpeculative(bool val) { mSpeculative = val; }
bool IsFromPredictor() { return mIsFromPredictor; }
void SetIsFromPredictor(bool val) { mIsFromPredictor = val; }
bool HasConnected() { return mHasConnected; }
void PrintDiagnostics(nsCString &log);
@ -471,6 +474,11 @@ private:
// more connections that are needed.)
bool mSpeculative;
// mIsFromPredictor is set if the socket originated from the network
// Predictor. It is used to gather telemetry data on used speculative
// connections from the predictor.
bool mIsFromPredictor;
TimeStamp mPrimarySynStarted;
TimeStamp mBackupSynStarted;
@ -541,7 +549,7 @@ private:
void ClosePersistentConnections(nsConnectionEntry *ent);
void ReportProxyTelemetry(nsConnectionEntry *ent);
nsresult CreateTransport(nsConnectionEntry *, nsAHttpTransaction *,
uint32_t, bool);
uint32_t, bool, bool = false);
void AddActiveConn(nsHttpConnection *, nsConnectionEntry *);
void DecrementActiveConnCount(nsHttpConnection *);
void StartedConnect();

View File

@ -2201,6 +2201,30 @@
"extended_statistics_ok": true,
"description": "How many actual preconnects happen"
},
"PREDICTOR_TOTAL_PRECONNECTS_CREATED": {
"expires_in_version": "never",
"kind": "exponential",
"high": "1000 * 1000",
"n_buckets": 50,
"extended_statistics_ok": true,
"description": "How many preconnects actually created a speculative socket"
},
"PREDICTOR_TOTAL_PRECONNECTS_USED": {
"expires_in_version": "never",
"kind": "exponential",
"high": "1000 * 1000",
"n_buckets": 50,
"extended_statistics_ok": true,
"description": "How many preconnects actually created a used speculative socket"
},
"PREDICTOR_TOTAL_PRECONNECTS_UNUSED": {
"expires_in_version": "never",
"kind": "exponential",
"high": "1000 * 1000",
"n_buckets": 50,
"extended_statistics_ok": true,
"description": "How many preconnects needlessly created a speculative socket"
},
"PREDICTOR_TOTAL_PRERESOLVES": {
"expires_in_version": "never",
"kind": "exponential",