diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-10 23:11:57 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-10 23:11:57 +0200 |
commit | 84cbeace33cdc2308fe42e8a8fe4a74411492202 (patch) | |
tree | bbad05d734e36836c2309568330616a78af80216 /jdisc_core/src | |
parent | 78fbd3b29837066e5d1b43efd70df6c01ed2a34f (diff) |
Since Q size is only used in tests, gather it insteda of doing double bookkeeping.
Diffstat (limited to 'jdisc_core/src')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java | 8 | ||||
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java | 11 |
2 files changed, 14 insertions, 5 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 29ac57a24a1..397271d0b48 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 @@ -60,6 +60,14 @@ class ScheduledQueue { } } + synchronized int queueSize() { + int sum = 0; + for (int cnt : counts) { + sum += cnt; + } + return sum; + } + private synchronized void scheduleAt(Entry entry, long expireAtMillis) { if (entry.next != null) { linkOut(entry); 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 49b5f685a7c..bb1ffce1c86 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 @@ -34,7 +34,6 @@ public class TimeoutManagerImpl { private final Thread thread; private final Timer timer; private final AtomicInteger nextScheduler = new AtomicInteger(0); - private final AtomicInteger queueSize = new AtomicInteger(0); private final AtomicBoolean done = new AtomicBoolean(false); @Inject @@ -61,8 +60,12 @@ public class TimeoutManagerImpl { return new ManagedRequestHandler(handler); } - int queueSize() { - return queueSize.get(); // unstable snapshot, only for test purposes + synchronized int queueSize() { + int sum = 0; + for (ScheduledQueue schedule : schedules) { + sum += schedule.queueSize(); + } + return sum; } Timer timer() { @@ -198,7 +201,6 @@ public class TimeoutManagerImpl { timeoutQueueEntry = schedules[(nextScheduler.incrementAndGet() & 0xffff) % schedules.length].newEntry(this); } timeoutQueueEntry.scheduleAt(request.creationTime(TimeUnit.MILLISECONDS) + request.getTimeout(TimeUnit.MILLISECONDS)); - queueSize.incrementAndGet(); } synchronized void unscheduleTimeout() { @@ -208,7 +210,6 @@ public class TimeoutManagerImpl { //followed by unscheduling in another thread from TimeoutHandler.handleResponse timeoutQueueEntry = null; } - queueSize.decrementAndGet(); } @Override |