summaryrefslogtreecommitdiffstats
path: root/jdisc_core
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2023-04-28 16:45:07 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2023-04-28 16:45:07 +0200
commit6ee092ad28e88f97d73fe3b1986b0135f4388f6c (patch)
treed3a2040e32f1d4f81cab2cb1a86b07a21354314f /jdisc_core
parent9c04252f9c8573bdbb787b5e3a0f671487eb412e (diff)
No need for multiple schedulers
Diffstat (limited to 'jdisc_core')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java24
1 files changed, 5 insertions, 19 deletions
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 d7b652b80f7..a2952087da3 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
@@ -19,7 +19,6 @@ import java.util.Queue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -30,10 +29,9 @@ public class TimeoutManagerImpl {
private static final ContentChannel IGNORED_CONTENT = new IgnoredContent();
private static final Logger log = Logger.getLogger(TimeoutManagerImpl.class.getName());
- private final ScheduledQueue [] schedules = new ScheduledQueue[Runtime.getRuntime().availableProcessors()];
+ private final ScheduledQueue scheduler;
private final Thread thread;
private final Timer timer;
- private final AtomicInteger nextScheduler = new AtomicInteger(0);
private final AtomicBoolean done = new AtomicBoolean(false);
@Inject
@@ -41,11 +39,7 @@ public class TimeoutManagerImpl {
this.thread = factory.newThread(new ManagerTask());
this.thread.setName(getClass().getName());
this.timer = timer;
-
- long now = timer.currentTimeMillis();
- for (int i = 0; i < schedules.length; ++i) {
- schedules[i] = new ScheduledQueue(now);
- }
+ this.scheduler = new ScheduledQueue(timer.currentTimeMillis());
}
public void start() {
@@ -66,13 +60,7 @@ public class TimeoutManagerImpl {
return new ManagedRequestHandler(handler);
}
- synchronized int queueSize() {
- int sum = 0;
- for (ScheduledQueue schedule : schedules) {
- sum += schedule.queueSize();
- }
- return sum;
- }
+ synchronized int queueSize() { return scheduler.queueSize(); }
Timer timer() {
return timer;
@@ -80,9 +68,7 @@ public class TimeoutManagerImpl {
void checkTasks(long currentTimeMillis) {
Queue<Object> queue = new LinkedList<>();
- for (ScheduledQueue schedule : schedules) {
- schedule.drainTo(currentTimeMillis, queue);
- }
+ scheduler.drainTo(currentTimeMillis, queue);
while (!queue.isEmpty()) {
TimeoutHandler timeoutHandler = (TimeoutHandler)queue.poll();
invokeTimeout(timeoutHandler.requestHandler, timeoutHandler.request, timeoutHandler);
@@ -204,7 +190,7 @@ public class TimeoutManagerImpl {
return;
}
if (timeoutQueueEntry == null) {
- timeoutQueueEntry = schedules[(nextScheduler.incrementAndGet() & 0xffff) % schedules.length].newEntry(this);
+ timeoutQueueEntry = scheduler.newEntry(this);
}
timeoutQueueEntry.scheduleAt(request.creationTime(TimeUnit.MILLISECONDS) + request.getTimeout(TimeUnit.MILLISECONDS));
}