Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 7acac25

Browse files
committed
bug 819734 - Token Bucket for Network Requests [a/b test] r=honzab
1 parent 3cdb8b8 commit 7acac25

13 files changed

Lines changed: 293 additions & 43 deletions

File tree

docshell/base/nsDocShell.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
// so we can associate the document URI with the load group.
9595
// until this point, we have an evil hack:
9696
#include "nsIHttpChannelInternal.h"
97-
97+
#include "nsPILoadGroupInternal.h"
9898

9999
// Local Includes
100100
#include "nsDocShellLoadInfo.h"
@@ -6548,10 +6548,15 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress,
65486548
if (timingChannel) {
65496549
TimeStamp channelCreationTime;
65506550
rv = timingChannel->GetChannelCreation(&channelCreationTime);
6551-
if (NS_SUCCEEDED(rv) && !channelCreationTime.IsNull())
6551+
if (NS_SUCCEEDED(rv) && !channelCreationTime.IsNull()) {
65526552
Telemetry::AccumulateTimeDelta(
65536553
Telemetry::TOTAL_CONTENT_PAGE_LOAD_TIME,
65546554
channelCreationTime);
6555+
nsCOMPtr<nsPILoadGroupInternal> internalLoadGroup =
6556+
do_QueryInterface(mLoadGroup);
6557+
if (internalLoadGroup)
6558+
internalLoadGroup->OnEndPageLoad(aChannel);
6559+
}
65556560
}
65566561

65576562
// Timing is picked up by the window, we don't need it anymore

modules/libpref/src/init/all.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,13 @@ pref("network.http.spdy.send-buffer-size", 131072);
10031003

10041004
pref("network.http.diagnostics", false);
10051005

1006+
#ifdef RELEASE_BUILD
10061007
pref("network.http.pacing.requests.enabled", false);
1008+
pref("network.http.pacing.requests.abtest", false);
1009+
#else
1010+
pref("network.http.pacing.requests.enabled", true);
1011+
pref("network.http.pacing.requests.abtest", true);
1012+
#endif
10071013
pref("network.http.pacing.requests.min-parallelism", 6);
10081014
pref("network.http.pacing.requests.hz", 100);
10091015
pref("network.http.pacing.requests.burst", 32);

netwerk/base/public/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ XPIDL_SOURCES += [
108108
'nsIUploadChannel.idl',
109109
'nsIUploadChannel2.idl',
110110
'nsPISocketTransportService.idl',
111+
'nsPILoadGroupInternal.idl',
111112
]
112113

113114
if CONFIG['MOZ_TOOLKIT_SEARCH']:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "nsISupports.idl"
7+
8+
interface nsIChannel;
9+
10+
/**
11+
* Dumping ground for load group experimental work.
12+
* This interface will never be frozen. If you are
13+
* using any feature exposed by this interface, be aware that this interface
14+
* will change and you will be broken. You have been warned.
15+
*/
16+
[scriptable, uuid(6ef2f8ac-9584-48f3-957a-0c94fff0c8c7)]
17+
interface nsPILoadGroupInternal : nsISupports
18+
{
19+
20+
/**
21+
* Called when the load group has loaded main page and
22+
* subresources. (i.e.essentially DOMComplete)
23+
*
24+
* @param aDefaultChanel
25+
* The request channel for the base apge
26+
*/
27+
void OnEndPageLoad(in nsIChannel aDefaultChannel);
28+
};

netwerk/base/src/nsLoadGroup.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "nsReadableUtils.h"
2222
#include "nsString.h"
2323
#include "nsTArray.h"
24+
#include "nsIHttpChannelInternal.h"
2425
#include "mozilla/Telemetry.h"
2526

2627
using namespace mozilla;
@@ -117,6 +118,7 @@ nsLoadGroup::nsLoadGroup(nsISupports* outer)
117118
, mDefaultLoadIsTimed(false)
118119
, mTimedRequests(0)
119120
, mCachedRequests(0)
121+
, mTimedNonCachedRequestsUntilOnEndPageLoad(0)
120122
{
121123
NS_INIT_AGGREGATED(outer);
122124

@@ -155,6 +157,7 @@ nsLoadGroup::~nsLoadGroup()
155157
NS_IMPL_AGGREGATED(nsLoadGroup)
156158
NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsLoadGroup)
157159
NS_INTERFACE_MAP_ENTRY(nsILoadGroup)
160+
NS_INTERFACE_MAP_ENTRY(nsPILoadGroupInternal)
158161
NS_INTERFACE_MAP_ENTRY(nsILoadGroupChild)
159162
NS_INTERFACE_MAP_ENTRY(nsIRequest)
160163
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
@@ -631,8 +634,12 @@ nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
631634
++mTimedRequests;
632635
TimeStamp timeStamp;
633636
rv = timedChannel->GetCacheReadStart(&timeStamp);
634-
if (NS_SUCCEEDED(rv) && !timeStamp.IsNull())
637+
if (NS_SUCCEEDED(rv) && !timeStamp.IsNull()) {
635638
++mCachedRequests;
639+
}
640+
else {
641+
mTimedNonCachedRequestsUntilOnEndPageLoad++;
642+
}
636643

637644
rv = timedChannel->GetAsyncOpen(&timeStamp);
638645
if (NS_SUCCEEDED(rv) && !timeStamp.IsNull()) {
@@ -812,6 +819,52 @@ nsLoadGroup::GetRootLoadGroup(nsILoadGroup * *aRootLoadGroup)
812819
return NS_OK;
813820
}
814821

822+
////////////////////////////////////////////////////////////////////////////////
823+
// nsPILoadGroupInternal methods:
824+
825+
NS_IMETHODIMP
826+
nsLoadGroup::OnEndPageLoad(nsIChannel *aDefaultChannel)
827+
{
828+
// On page load of a page with at least 32 resources we want to record
829+
// telemetry on which rate pacing algorithm was used to load the page and
830+
// the page load time.
831+
uint32_t requests = mTimedNonCachedRequestsUntilOnEndPageLoad;
832+
mTimedNonCachedRequestsUntilOnEndPageLoad = 0;
833+
834+
nsCOMPtr<nsITimedChannel> timedChannel =
835+
do_QueryInterface(aDefaultChannel);
836+
if (!timedChannel)
837+
return NS_OK;
838+
839+
nsCOMPtr<nsIHttpChannelInternal> internalHttpChannel =
840+
do_QueryInterface(timedChannel);
841+
if (!internalHttpChannel)
842+
return NS_OK;
843+
844+
TimeStamp cacheReadStart;
845+
TimeStamp asyncOpen;
846+
uint32_t telemetryID;
847+
nsresult rv = timedChannel->GetCacheReadStart(&cacheReadStart);
848+
if (NS_SUCCEEDED(rv))
849+
rv = timedChannel->GetAsyncOpen(&asyncOpen);
850+
if (NS_SUCCEEDED(rv))
851+
rv = internalHttpChannel->GetPacingTelemetryID(&telemetryID);
852+
if (NS_FAILED(rv))
853+
return NS_OK;
854+
855+
// Nothing to do if we don't have a start time or this was
856+
// from the cache or we don't know what profile was used
857+
if (asyncOpen.IsNull() || !cacheReadStart.IsNull() || !telemetryID)
858+
return NS_OK;
859+
860+
if (requests < 32)
861+
return NS_OK;
862+
863+
Telemetry::AccumulateTimeDelta(static_cast<Telemetry::ID>(telemetryID),
864+
asyncOpen);
865+
return NS_OK;
866+
}
867+
815868
////////////////////////////////////////////////////////////////////////////////
816869
// nsISupportsPriority methods:
817870

netwerk/base/src/nsLoadGroup.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "nsILoadGroup.h"
1010
#include "nsILoadGroupChild.h"
11+
#include "nsPILoadGroupInternal.h"
1112
#include "nsIChannel.h"
1213
#include "nsIStreamListener.h"
1314
#include "nsAgg.h"
@@ -26,7 +27,8 @@ class nsILoadGroupConnectionInfo;
2627
class nsLoadGroup : public nsILoadGroup,
2728
public nsILoadGroupChild,
2829
public nsISupportsPriority,
29-
public nsSupportsWeakReference
30+
public nsSupportsWeakReference,
31+
public nsPILoadGroupInternal
3032
{
3133
public:
3234
NS_DECL_AGGREGATED
@@ -38,6 +40,7 @@ class nsLoadGroup : public nsILoadGroup,
3840
////////////////////////////////////////////////////////////////////////////
3941
// nsILoadGroup methods:
4042
NS_DECL_NSILOADGROUP
43+
NS_DECL_NSPILOADGROUPINTERNAL
4144

4245
////////////////////////////////////////////////////////////////////////////
4346
// nsILoadGroupChild methods:
@@ -87,6 +90,9 @@ class nsLoadGroup : public nsILoadGroup,
8790
bool mDefaultLoadIsTimed;
8891
uint32_t mTimedRequests;
8992
uint32_t mCachedRequests;
93+
94+
/* For nsPILoadGroupInternal */
95+
uint32_t mTimedNonCachedRequestsUntilOnEndPageLoad;
9096
};
9197

9298
#endif // nsLoadGroup_h__

netwerk/protocol/http/HttpBaseChannel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,17 @@ HttpBaseChannel::SetLoadUnblocked(bool aLoadUnblocked)
13991399
return NS_OK;
14001400
}
14011401

1402+
NS_IMETHODIMP
1403+
HttpBaseChannel::GetPacingTelemetryID(uint32_t *aID)
1404+
{
1405+
*aID = 0;
1406+
// Don't record pacing algorithm for spdy because it is effectively
1407+
// bypassed by the protocol mux
1408+
if (!mResponseHead || !mResponseHead->PeekHeader(nsHttp::X_Firefox_Spdy))
1409+
*aID = gHttpHandler->PacingTelemetryID();
1410+
return NS_OK;
1411+
}
1412+
14021413
//-----------------------------------------------------------------------------
14031414
// HttpBaseChannel::nsISupportsPriority
14041415
//-----------------------------------------------------------------------------

netwerk/protocol/http/HttpBaseChannel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class HttpBaseChannel : public nsHashPropertyBag
149149
NS_IMETHOD SetLoadAsBlocking(bool aLoadAsBlocking);
150150
NS_IMETHOD GetLoadUnblocked(bool *aLoadUnblocked);
151151
NS_IMETHOD SetLoadUnblocked(bool aLoadUnblocked);
152+
NS_IMETHOD GetPacingTelemetryID(uint32_t *aID);
152153

153154
inline void CleanRedirectCacheChainIfNecessary()
154155
{

netwerk/protocol/http/nsHttpAtomList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ HTTP_ATOM(Vary, "Vary")
8585
HTTP_ATOM(Version, "Version")
8686
HTTP_ATOM(WWW_Authenticate, "WWW-Authenticate")
8787
HTTP_ATOM(Warning, "Warning")
88+
HTTP_ATOM(X_Firefox_Spdy, "X-Firefox-Spdy")
8889

8990
// methods are atoms too.
9091
//

0 commit comments

Comments
 (0)