Title: [197415] trunk/Source/WebCore
Revision
197415
Author
[email protected]
Date
2016-03-01 15:33:36 -0800 (Tue, 01 Mar 2016)

Log Message

Timer alignment in separate web processes should not all sync up to the same point.
https://bugs.webkit.org/show_bug.cgi?id=154878

Reviewed by Chris Dumez.

For any given WebContent process it is desirable that timers are synchronized to a single
alignment point, but if all WebContent processes align to the same point then there may
be a thundering herd of processes waking up.

* page/DOMTimer.cpp:
(WebCore::DOMTimer::alignedFireTime):
    - align to a randomized point.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197414 => 197415)


--- trunk/Source/WebCore/ChangeLog	2016-03-01 22:29:39 UTC (rev 197414)
+++ trunk/Source/WebCore/ChangeLog	2016-03-01 23:33:36 UTC (rev 197415)
@@ -1,3 +1,18 @@
+2016-03-01  Gavin Barraclough  <[email protected]>
+
+        Timer alignment in separate web processes should not all sync up to the same point.
+        https://bugs.webkit.org/show_bug.cgi?id=154878
+
+        Reviewed by Chris Dumez.
+
+        For any given WebContent process it is desirable that timers are synchronized to a single
+        alignment point, but if all WebContent processes align to the same point then there may
+        be a thundering herd of processes waking up.
+
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::alignedFireTime):
+            - align to a randomized point.
+
 2016-03-01  Alex Christensen  <[email protected]>
 
         Reduce size of internal windows build output

Modified: trunk/Source/WebCore/page/DOMTimer.cpp (197414 => 197415)


--- trunk/Source/WebCore/page/DOMTimer.cpp	2016-03-01 22:29:39 UTC (rev 197414)
+++ trunk/Source/WebCore/page/DOMTimer.cpp	2016-03-01 23:33:36 UTC (rev 197415)
@@ -40,6 +40,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/MathExtras.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/RandomNumber.h>
 #include <wtf/StdLibExtras.h>
 
 #if PLATFORM(IOS)
@@ -422,8 +423,15 @@
 
 double DOMTimer::alignedFireTime(double fireTime) const
 {
-    if (double alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel))
-        return ceil(fireTime / alignmentInterval) * alignmentInterval;
+    if (double alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel)) {
+        // Don't mess with zero-delay timers.
+        if (!fireTime)
+            return fireTime;
+        static const double randomizedAlignment = randomNumber();
+        // Force alignment to randomizedAlignment fraction of the way between alignemntIntervals, e.g.
+        // if alignmentInterval is 10 and randomizedAlignment is 0.3 this will align to 3, 13, 23, ...
+        return (ceil(fireTime / alignmentInterval - randomizedAlignment) + randomizedAlignment) * alignmentInterval;
+    }
 
     return fireTime;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to