WebKit Bugzilla
Attachment 369166 Details for
Bug 197626
: Terminate service workers that use too much CPU / power
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-197626-20190506134743.patch (text/plain), 5.60 KB, created by
Chris Dumez
on 2019-05-06 13:47:43 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2019-05-06 13:47:43 PDT
Size:
5.60 KB
patch
obsolete
>Subversion Revision: 244966 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index c7fe70b3fbeb31c435e1db53999dde573ddfdab8..b7dd6bde2af005c22a4319b6ee2e7a3ae1310d1f 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,22 @@ >+2019-05-06 Chris Dumez <cdumez@apple.com> >+ >+ Terminate service workers that use too much CPU / power >+ https://bugs.webkit.org/show_bug.cgi?id=197626 >+ <rdar://problem/50374707> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Terminate service worker processes that use over 50% CPU on average over the last 8 minutes, >+ similarly to what we do for background WebContent processes. >+ >+ * UIProcess/WebProcessProxy.cpp: >+ (WebKit::WebProcessProxy::didExceedCPULimit): >+ * WebProcess/WebProcess.cpp: >+ (WebKit::WebProcess::initializeProcess): >+ * WebProcess/cocoa/WebProcessCocoa.mm: >+ (WebKit::WebProcess::updateCPULimit): >+ (WebKit::WebProcess::updateCPUMonitorState): >+ > 2019-05-06 Wenson Hsieh <wenson_hsieh@apple.com> > > Introduce SPI to request modern compatibility mode but defer to site-specific quirks >diff --git a/Source/WebKit/UIProcess/WebProcessProxy.cpp b/Source/WebKit/UIProcess/WebProcessProxy.cpp >index d4f37d7cb5295caf5574851554558699e1492917..41d300440c19daa1195aad39dcc23be06cbd6d38 100644 >--- a/Source/WebKit/UIProcess/WebProcessProxy.cpp >+++ b/Source/WebKit/UIProcess/WebProcessProxy.cpp >@@ -1338,7 +1338,10 @@ void WebProcessProxy::didExceedCPULimit() > if (hasVisiblePage) > return; > >- RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating background WebProcess with pid %d that has exceeded the background CPU limit", this, processIdentifier()); >+ if (isServiceWorkerProcess()) >+ RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating Service Worker process with pid %d that has exceeded the background CPU limit", this, processIdentifier()); >+ else >+ RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating background WebProcess with pid %d that has exceeded the background CPU limit", this, processIdentifier()); > logDiagnosticMessageForResourceLimitTermination(DiagnosticLoggingKeys::exceededBackgroundCPULimitKey()); > requestTermination(ProcessTerminationReason::ExceededCPULimit); > } >diff --git a/Source/WebKit/WebProcess/WebProcess.cpp b/Source/WebKit/WebProcess/WebProcess.cpp >index 7159766e6dc83f5da399f14b11fa41c64b002f7e..6fa34f0e1ed1754a6df0193f3cee72cfc3438cb2 100644 >--- a/Source/WebKit/WebProcess/WebProcess.cpp >+++ b/Source/WebKit/WebProcess/WebProcess.cpp >@@ -237,6 +237,7 @@ void WebProcess::initializeProcess(const AuxiliaryProcessInitializationParameter > MessagePortChannelProvider::setSharedProvider(WebMessagePortChannelProvider::singleton()); > > platformInitializeProcess(parameters); >+ updateCPULimit(); > } > > void WebProcess::initializeConnection(IPC::Connection* connection) >diff --git a/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm b/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm >index 73df75c86dda1237eaf5b9cc4d33639dbc83117d..e6a7a562945c5c0159d4db5e0416706ba1365e52 100644 >--- a/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm >+++ b/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm >@@ -121,6 +121,7 @@ using namespace WebCore; > > #if PLATFORM(MAC) > static const Seconds cpuMonitoringInterval { 8_min }; >+static const double serviceWorkerCPULimit { 0.5 }; // 50% average CPU usage over 8 minutes. > #endif > > void WebProcess::platformSetCacheModel(CacheModel) >@@ -577,16 +578,19 @@ void WebProcess::updateCPULimit() > { > #if PLATFORM(MAC) > Optional<double> cpuLimit; >- >- // Use the largest limit among all pages in this process. >- for (auto& page : m_pageMap.values()) { >- auto pageCPULimit = page->cpuLimit(); >- if (!pageCPULimit) { >- cpuLimit = WTF::nullopt; >- break; >+ if (m_processType == ProcessType::ServiceWorker) >+ cpuLimit = serviceWorkerCPULimit; >+ else { >+ // Use the largest limit among all pages in this process. >+ for (auto& page : m_pageMap.values()) { >+ auto pageCPULimit = page->cpuLimit(); >+ if (!pageCPULimit) { >+ cpuLimit = WTF::nullopt; >+ break; >+ } >+ if (!cpuLimit || pageCPULimit > cpuLimit.value()) >+ cpuLimit = pageCPULimit; > } >- if (!cpuLimit || pageCPULimit > cpuLimit.value()) >- cpuLimit = pageCPULimit; > } > > if (m_cpuLimit == cpuLimit) >@@ -608,7 +612,10 @@ void WebProcess::updateCPUMonitorState(CPUMonitorUpdateReason reason) > > if (!m_cpuMonitor) { > m_cpuMonitor = std::make_unique<CPUMonitor>(cpuMonitoringInterval, [this](double cpuUsage) { >- RELEASE_LOG(PerformanceLogging, "%p - WebProcess exceeded CPU limit of %.1f%% (was using %.1f%%) hasVisiblePages? %d", this, m_cpuLimit.value() * 100, cpuUsage * 100, hasVisibleWebPage()); >+ if (m_processType == ProcessType::ServiceWorker) >+ RELEASE_LOG_ERROR(PerformanceLogging, "%p - Service worker process exceeded CPU limit of %.1f%% (was using %.1f%%)", this, m_cpuLimit.value() * 100, cpuUsage * 100); >+ else >+ RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcess exceeded CPU limit of %.1f%% (was using %.1f%%) hasVisiblePages? %d", this, m_cpuLimit.value() * 100, cpuUsage * 100, hasVisibleWebPage()); > parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedCPULimit(), 0); > }); > } else if (reason == CPUMonitorUpdateReason::VisibilityHasChanged) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197626
: 369166