diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 23:46:57 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-03 23:46:57 +0100 |
commit | 2ccd749f26db9e6832f7f15b60cd1937d2aa291d (patch) | |
tree | 17f4fad6150bad4c0ae1e7fd80d466389ce965ae /messagebus | |
parent | 4a5c54e6e3780f7a02d83ec325938317ef3837b1 (diff) |
Avoid the excessive ping-pong when many threads are blocking.
If less then 100 give all a chance to send, if more only select 1.
Diffstat (limited to 'messagebus')
-rw-r--r-- | messagebus/src/main/java/com/yahoo/messagebus/SourceSession.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/messagebus/src/main/java/com/yahoo/messagebus/SourceSession.java b/messagebus/src/main/java/com/yahoo/messagebus/SourceSession.java index bef6e37476c..6f8e0903e9b 100644 --- a/messagebus/src/main/java/com/yahoo/messagebus/SourceSession.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/SourceSession.java @@ -26,6 +26,7 @@ public final class SourceSession implements ReplyHandler { private final ThrottlePolicy throttlePolicy; private volatile double timeout; private volatile int pendingCount = 0; + private int blockedCount = 0; private boolean closed = false; /** @@ -172,8 +173,13 @@ public final class SourceSession implements ReplyHandler { return res; } synchronized (lock) { - while (!closed && !throttlePolicy.canSend(msg, pendingCount)) { - lock.wait(100); + try { + blockedCount++; + while (!closed && !throttlePolicy.canSend(msg, pendingCount)) { + lock.wait(100); + } + } finally { + blockedCount--; } } } @@ -192,7 +198,11 @@ public final class SourceSession implements ReplyHandler { throttlePolicy.processReply(reply); } done = (closed && pendingCount == 0); - lock.notifyAll(); + if (blockedCount < 100) { + lock.notifyAll(); + } else { + lock.notify(); + } } if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, |