You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2014/04/24 15:12:22 UTC

svn commit: r1589712 - in /jackrabbit/oak/branches/1.0: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java

Author: mduerig
Date: Thu Apr 24 13:12:22 2014
New Revision: 1589712

URL: http://svn.apache.org/r1589712
Log:
OAK-1757: Oak eats too many CPU cycles when idle Make the Fast clock update interval configurable for testing purposes Update test case to judge drift against correct clock granularity

Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java
    jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk:r1589708

Modified: jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java?rev=1589712&r1=1589711&r2=1589712&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java (original)
+++ jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/Clock.java Thu Apr 24 13:12:22 2014
@@ -46,12 +46,17 @@ public abstract class Clock {
             Long.getLong("accurate.clock.granularity", 1);
 
     /**
+     * Default value for {@link #FAST_CLOCK_INTERVAL}
+     */
+    public static final long DEFAULT_FAST_CLOCK_INTERVAL = 1;
+
+    /**
      * Millisecond update interval of the {@link Fast} clock. Configurable
      * by the "fast.clock.interval" system property to to make it easier
      * to test the effect of different update frequencies.
      */
     private static final long FAST_CLOCK_INTERVAL =
-            Long.getLong("fast.clock.interval", 10);
+            Long.getLong("fast.clock.interval", DEFAULT_FAST_CLOCK_INTERVAL);
 
     private long monotonic = 0;
 

Modified: jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java?rev=1589712&r1=1589711&r2=1589712&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-core/src/test/java/org/apache/jackrabbit/oak/stats/ClockTest.java Thu Apr 24 13:12:22 2014
@@ -21,9 +21,13 @@ import static junit.framework.Assert.ass
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 
+import org.apache.jackrabbit.oak.stats.Clock.Fast;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class ClockTest {
+    private static long SYSTEM_CLOCK_GRANULARITY;
+    private static Long FAST_CLOCK_GRANULARITY;
 
     /**
      * Helper for checking how accurate the system clock is.
@@ -33,19 +37,17 @@ public class ClockTest {
                 "average clock granularity: " + getAverageClockGranularity());
     }
 
+    @BeforeClass
+    public static void setup() {
+        SYSTEM_CLOCK_GRANULARITY = getAverageClockGranularity();
+        FAST_CLOCK_GRANULARITY = 1000 * Long.getLong("fast.clock.interval", Clock.DEFAULT_FAST_CLOCK_INTERVAL);
+    }
+
     @Test
     public void testClockDrift() throws InterruptedException {
         ScheduledExecutorService executor =
                 Executors.newSingleThreadScheduledExecutor();
 
-        // Set the drift limit to twice as high as granularity,
-        // plus 3ms for Thread.sleep() inaccuracy in the fast clock
-        final long granularity = getAverageClockGranularity();
-        final long limit = (2 * granularity) / 1000 + 3;
-        final String diag =
-                "(estimated limit was " + limit + "ms,"
-                + " measured granularity was " + (granularity / 1000f) + "ms)";
-
         try {
             Clock[] clocks = new Clock[] {
                     Clock.SIMPLE,
@@ -55,8 +57,14 @@ public class ClockTest {
 
             for (Clock clock : clocks) {
                 long drift = clock.getTime() - System.currentTimeMillis();
+
+                // Set the drift limit to twice as high as granularity,
+                // plus 3ms for Thread.sleep() inaccuracy in the fast clock
+                final long granularity = getGranularity(clock);
+                final long limit = (2 * granularity) / 1000 + 3;
                 assertTrue(
-                        clock + " unexpected drift: " + drift + "ms " + diag,
+                        clock + " unexpected drift: " + drift + "ms (estimated limit was " +
+                                limit + "ms, measured granularity was " + (granularity / 1000f) + "ms)",
                         Math.abs(drift) <= limit);
             }
 
@@ -64,8 +72,14 @@ public class ClockTest {
 
             for (Clock clock : clocks) {
                 long drift = clock.getTime() - System.currentTimeMillis();
+
+                // Set the drift limit to twice as high as granularity,
+                // plus 3ms for Thread.sleep() inaccuracy in the fast clock
+                final long granularity = getGranularity(clock);
+                final long limit = (2 * granularity) / 1000 + 3;
                 assertTrue(
-                        clock + " unexpected drift ater 100ms: " + drift + "ms " + diag,
+                        clock + " unexpected drift ater 100ms: " + drift + "ms (estimated limit was " +
+                                limit + "ms, measured granularity was " + (granularity / 1000f) + "ms)",
                         Math.abs(drift) <= limit);
             }
         } finally {
@@ -73,6 +87,12 @@ public class ClockTest {
         }
     }
 
+    private static long getGranularity(Clock clock) {
+        return clock instanceof Fast
+            ? FAST_CLOCK_GRANULARITY
+            : SYSTEM_CLOCK_GRANULARITY;
+    }
+
     @Test
     public void testClockIncreasing() throws InterruptedException {
         ScheduledExecutorService executor =