Title: [244979] trunk/Source/WebKit
- Revision
- 244979
- Author
- cdu...@apple.com
- Date
- 2019-05-06 14:44:01 -0700 (Mon, 06 May 2019)
Log Message
Terminate service workers that use too much CPU / power
https://bugs.webkit.org/show_bug.cgi?id=197626
<rdar://problem/50374707>
Reviewed by Geoffrey Garen.
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):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (244978 => 244979)
--- trunk/Source/WebKit/ChangeLog 2019-05-06 21:33:27 UTC (rev 244978)
+++ trunk/Source/WebKit/ChangeLog 2019-05-06 21:44:01 UTC (rev 244979)
@@ -1,3 +1,22 @@
+2019-05-06 Chris Dumez <cdu...@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 Geoffrey Garen.
+
+ 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 Daniel Bates <daba...@apple.com>
Google Docs & Yahoo! Japan: Can’t compose characters with Chinese or Japanese keyboard
Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (244978 => 244979)
--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2019-05-06 21:33:27 UTC (rev 244978)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2019-05-06 21:44:01 UTC (rev 244979)
@@ -1338,7 +1338,10 @@
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);
}
Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (244978 => 244979)
--- trunk/Source/WebKit/WebProcess/WebProcess.cpp 2019-05-06 21:33:27 UTC (rev 244978)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp 2019-05-06 21:44:01 UTC (rev 244979)
@@ -237,6 +237,7 @@
MessagePortChannelProvider::setSharedProvider(WebMessagePortChannelProvider::singleton());
platformInitializeProcess(parameters);
+ updateCPULimit();
}
void WebProcess::initializeConnection(IPC::Connection* connection)
Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (244978 => 244979)
--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2019-05-06 21:33:27 UTC (rev 244978)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2019-05-06 21:44:01 UTC (rev 244979)
@@ -121,6 +121,7 @@
#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 @@
{
#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 @@
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) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes