Skip to content

Commit

Permalink
Bug 1139513 - Warn and gather data if ServiceWorker hits max workers …
Browse files Browse the repository at this point in the history
…per domain limit. r=bent, r=rvitillo
  • Loading branch information
jaoo committed Mar 25, 2015
1 parent 987f6f9 commit 60663a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dom/locales/en-US/chrome/dom/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,5 @@ XMLDocumentLoadPrincipalMismatch=Use of document.load forbidden on Documents tha
IndexedDBTransactionAbortNavigation=An IndexedDB transaction that was not yet complete has been aborted due to page navigation.
# LOCALIZATION NOTE (WillChangeBudgetWarning): Do not translate Will-change, %1$S,%2$S,%3$S are numbers.
WillChangeBudgetWarning=Will-change memory consumption is too high. Surface area covers %1$S pixels, budget is the document surface area multiplied by %2$S (%3$S pixels). All occurences of will-change in the document are ignored when over budget.
# LOCALIZATION NOTE: Do not translate "ServiceWorker".
HittingMaxWorkersPerDomain=A ServiceWorker could not be started immediately because other documents in the same origin are already using the maximum number of workers. The ServiceWorker is now queued and will be started after some of the other workers have completed.
25 changes: 25 additions & 0 deletions dom/workers/RuntimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "nsIObserverService.h"
#include "nsIPrincipal.h"
#include "nsIScriptContext.h"
#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
#include "nsISupportsPriority.h"
#include "nsITimer.h"
Expand All @@ -26,6 +27,7 @@
#include "jsfriendapi.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/AtomList.h"
Expand Down Expand Up @@ -1414,6 +1416,12 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate)

nsCString sharedWorkerScriptSpec;

const bool isServiceWorker = aWorkerPrivate->IsServiceWorker();
if (isServiceWorker) {
AssertIsOnMainThread();
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_SPAWN_ATTEMPTS, 1);
}

bool isSharedOrServiceWorker = aWorkerPrivate->IsSharedWorker() ||
aWorkerPrivate->IsServiceWorker();
if (isSharedOrServiceWorker) {
Expand Down Expand Up @@ -1461,6 +1469,19 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate)

if (queued) {
domainInfo->mQueuedWorkers.AppendElement(aWorkerPrivate);
if (isServiceWorker) {
AssertIsOnMainThread();
// ServiceWorker spawn gets queued due to hitting max workers per domain
// limit so let's log a warning.
// Note: aWorkerPrivate->GetDocument() call might result nullptr due to
// no window so the message warning will show up in the browser console.
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("DOM"),
aWorkerPrivate->GetDocument(),
nsContentUtils::eDOM_PROPERTIES,
"HittingMaxWorkersPerDomain");
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_SPAWN_GETS_QUEUED, 1);
}
}
else if (parent) {
domainInfo->mChildWorkerCount++;
Expand Down Expand Up @@ -1529,6 +1550,10 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
return false;
}

if (isServiceWorker) {
AssertIsOnMainThread();
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_WAS_SPAWNED, 1);
}
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions toolkit/components/telemetry/Histograms.json
Original file line number Diff line number Diff line change
Expand Up @@ -7697,5 +7697,20 @@
"expires_in_version": "never",
"kind": "count",
"description": "Count plugin hang notices in e10s"
},
"SERVICE_WORKER_SPAWN_ATTEMPTS": {
"expires_in_version": "50",
"kind": "count",
"description": "Count attempts to spawn a ServiceWorker for a domain"
},
"SERVICE_WORKER_WAS_SPAWNED": {
"expires_in_version": "50",
"kind": "count",
"description": "Count ServiceWorkers that really did get a thread created for them"
},
"SERVICE_WORKER_SPAWN_GETS_QUEUED": {
"expires_in_version": "50",
"kind": "count",
"description": "Tracking whether a ServiceWorker spawn gets queued due to hitting max workers per domain limit"
}
}

0 comments on commit 60663a3

Please sign in to comment.