diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-05-02 17:05:36 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-05-02 17:07:59 +0200 |
commit | d74f8441fd630471dd19fa816075cd64ba20ac09 (patch) | |
tree | b48e0cc6e92dfb175b1f587fd7c0fa843671169d /jdisc_core | |
parent | 2c23e6ba1ce3049494ba146f700927092282494f (diff) |
Increase timeout resolution from 100ms to 10ms
Diffstat (limited to 'jdisc_core')
3 files changed, 11 insertions, 7 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java index f41bb32127e..355d6aee43a 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java @@ -10,10 +10,10 @@ import java.util.Queue; */ class ScheduledQueue { - public static final int MILLIS_PER_SLOT = 100; - public static final int NUM_SLOTS = 512; - public static final int SLOT_MASK = 511; // bitmask to modulo NUM_SLOTS - public static final int ITER_SHIFT = 9; // number of bits to shift off SLOT_MASK + public static final int MILLIS_PER_SLOT = 10; + public static final int NUM_SLOTS = 1024; + public static final int SLOT_MASK = NUM_SLOTS - 1; // bitmask to modulo NUM_SLOTS + public static final int ITER_SHIFT = Integer.numberOfTrailingZeros(NUM_SLOTS); // number of bits to shift off SLOT_MASK private final Entry[] slots = new Entry[NUM_SLOTS + 1]; private final int[] counts = new int[NUM_SLOTS + 1]; diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java index 30c659f4f53..f1e86a7e9ef 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java @@ -2,6 +2,7 @@ package com.yahoo.jdisc.core; import com.google.inject.Inject; +import com.yahoo.concurrent.SystemTimer; import com.yahoo.jdisc.Request; import com.yahoo.jdisc.ResourceReference; import com.yahoo.jdisc.Response; @@ -14,6 +15,7 @@ import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.handler.ResponseHandler; import java.nio.ByteBuffer; +import java.time.Duration; import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.ThreadFactory; @@ -91,7 +93,7 @@ public class TimeoutManagerImpl { private class ManagerTask implements Runnable { - boolean oneMoreCheck(int timeoutMS) { + boolean oneMoreCheck(long timeoutMS) { synchronized (done) { if (!done.get()) { try { @@ -106,7 +108,9 @@ public class TimeoutManagerImpl { @Override public void run() { - while (oneMoreCheck(ScheduledQueue.MILLIS_PER_SLOT)) { + Duration desiredTimeout = Duration.ofMillis(ScheduledQueue.MILLIS_PER_SLOT); + Duration actualTimeout = SystemTimer.adjustTimeoutByDetectedHz(SystemTimer.adjustTimeoutByDetectedHz(desiredTimeout)); + while (oneMoreCheck(actualTimeout.toMillis())) { checkTasks(timer.currentTimeMillis()); } } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ScheduledQueueTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ScheduledQueueTestCase.java index 9fcfd49d4ee..b5eef973d5b 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ScheduledQueueTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ScheduledQueueTestCase.java @@ -93,7 +93,7 @@ public class ScheduledQueueTestCase { @Test void requireThatEntriesDoNotExpireMoreThanOnce() { ScheduledQueue queue = new ScheduledQueue(0); - Object foo = scheduleAt(queue, NUM_SLOTS * MILLIS_PER_SLOT + 50); + Object foo = scheduleAt(queue, NUM_SLOTS * MILLIS_PER_SLOT + MILLIS_PER_SLOT/2); long now = 0; for (int i = 0; i < NUM_SLOTS; ++i, now += MILLIS_PER_SLOT) { |