Changeset 244979 in webkit


Ignore:
Timestamp:
May 6, 2019 2:44:01 PM (5 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244975 r244979  
     12019-05-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Terminate service workers that use too much CPU / power
     4        https://bugs.webkit.org/show_bug.cgi?id=197626
     5        <rdar://problem/50374707>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Terminate service worker processes that use over 50% CPU on average over the last 8 minutes,
     10        similarly to what we do for background WebContent processes.
     11
     12        * UIProcess/WebProcessProxy.cpp:
     13        (WebKit::WebProcessProxy::didExceedCPULimit):
     14        * WebProcess/WebProcess.cpp:
     15        (WebKit::WebProcess::initializeProcess):
     16        * WebProcess/cocoa/WebProcessCocoa.mm:
     17        (WebKit::WebProcess::updateCPULimit):
     18        (WebKit::WebProcess::updateCPUMonitorState):
     19
    1202019-05-06  Daniel Bates  <dabates@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r244936 r244979  
    13391339        return;
    13401340
    1341     RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating background WebProcess with pid %d that has exceeded the background CPU limit", this, processIdentifier());
     1341    if (isServiceWorkerProcess())
     1342        RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating Service Worker process with pid %d that has exceeded the background CPU limit", this, processIdentifier());
     1343    else
     1344        RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcessProxy::didExceedCPULimit() Terminating background WebProcess with pid %d that has exceeded the background CPU limit", this, processIdentifier());
    13421345    logDiagnosticMessageForResourceLimitTermination(DiagnosticLoggingKeys::exceededBackgroundCPULimitKey());
    13431346    requestTermination(ProcessTerminationReason::ExceededCPULimit);
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r244091 r244979  
    238238   
    239239    platformInitializeProcess(parameters);
     240    updateCPULimit();
    240241}
    241242
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r244955 r244979  
    122122#if PLATFORM(MAC)
    123123static const Seconds cpuMonitoringInterval { 8_min };
     124static const double serviceWorkerCPULimit { 0.5 }; // 50% average CPU usage over 8 minutes.
    124125#endif
    125126
     
    578579#if PLATFORM(MAC)
    579580    Optional<double> cpuLimit;
    580 
    581     // Use the largest limit among all pages in this process.
    582     for (auto& page : m_pageMap.values()) {
    583         auto pageCPULimit = page->cpuLimit();
    584         if (!pageCPULimit) {
    585             cpuLimit = WTF::nullopt;
    586             break;
     581    if (m_processType == ProcessType::ServiceWorker)
     582        cpuLimit = serviceWorkerCPULimit;
     583    else {
     584        // Use the largest limit among all pages in this process.
     585        for (auto& page : m_pageMap.values()) {
     586            auto pageCPULimit = page->cpuLimit();
     587            if (!pageCPULimit) {
     588                cpuLimit = WTF::nullopt;
     589                break;
     590            }
     591            if (!cpuLimit || pageCPULimit > cpuLimit.value())
     592                cpuLimit = pageCPULimit;
    587593        }
    588         if (!cpuLimit || pageCPULimit > cpuLimit.value())
    589             cpuLimit = pageCPULimit;
    590594    }
    591595
     
    609613    if (!m_cpuMonitor) {
    610614        m_cpuMonitor = std::make_unique<CPUMonitor>(cpuMonitoringInterval, [this](double cpuUsage) {
    611             RELEASE_LOG(PerformanceLogging, "%p - WebProcess exceeded CPU limit of %.1f%% (was using %.1f%%) hasVisiblePages? %d", this, m_cpuLimit.value() * 100, cpuUsage * 100, hasVisibleWebPage());
     615            if (m_processType == ProcessType::ServiceWorker)
     616                RELEASE_LOG_ERROR(PerformanceLogging, "%p - Service worker process exceeded CPU limit of %.1f%% (was using %.1f%%)", this, m_cpuLimit.value() * 100, cpuUsage * 100);
     617            else
     618                RELEASE_LOG_ERROR(PerformanceLogging, "%p - WebProcess exceeded CPU limit of %.1f%% (was using %.1f%%) hasVisiblePages? %d", this, m_cpuLimit.value() * 100, cpuUsage * 100, hasVisibleWebPage());
    612619            parentProcessConnection()->send(Messages::WebProcessProxy::DidExceedCPULimit(), 0);
    613620        });
Note: See TracChangeset for help on using the changeset viewer.