diff options
Diffstat (limited to 'jdisc_core/src/main')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java | 24 | ||||
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java | 10 |
2 files changed, 18 insertions, 16 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 09483a7c7e5..457864929dc 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,11 +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 NUM_SLOTS_UNDILATED = 3; - 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 = 2; + 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]; @@ -35,17 +34,16 @@ class ScheduledQueue { if (slots[NUM_SLOTS] == null && currentTimeMillis < nextTick) { return; } - int queueSize = queueSize() + out.size(); drainTo(NUM_SLOTS, 0, out); - for (int i = 0; currentTimeMillis >= nextTick && (queueSize > out.size()); i++, nextTick += MILLIS_PER_SLOT) { - if (i < NUM_SLOTS_UNDILATED) { - if (++currSlot >= NUM_SLOTS) { - currSlot = 0; - currIter++; - } - drainTo(currSlot, currIter, out); + while (currentTimeMillis >= nextTick) { + if (++currSlot >= NUM_SLOTS) { + currSlot = 0; + currIter++; } + drainTo(currSlot, currIter, out); + nextTick += MILLIS_PER_SLOT; } + } private void drainTo(int slot, int iter, Queue<Object> out) { 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 7a3898b2946..4e651cb9013 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; @@ -60,7 +62,7 @@ public class TimeoutManagerImpl { return new ManagedRequestHandler(handler); } - synchronized int queueSize() { return scheduler.queueSize(); } + int queueSize() { return scheduler.queueSize(); } Timer timer() { return timer; @@ -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(desiredTimeout); + while (oneMoreCheck(actualTimeout.toMillis())) { checkTasks(timer.currentTimeMillis()); } } |