Repository: ignite
Updated Branches:
  refs/heads/ignite-comm-opts2 acc890ad8 -> 41665bab0


ignite-3220 Implemented separate in/out connections in communication.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/41665bab
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/41665bab
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/41665bab

Branch: refs/heads/ignite-comm-opts2
Commit: 41665bab051932ce77298ab0fd5a84ed99005db2
Parents: acc890a
Author: sboikov <sboi...@gridgain.com>
Authored: Thu Sep 15 13:15:11 2016 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Thu Sep 15 13:15:11 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/util/nio/GridNioServer.java    | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/41665bab/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
index ccd0ae4..578c73e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
@@ -45,6 +45,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
@@ -146,9 +147,13 @@ public class GridNioServer<T> {
     /** Flag indicating if this server should use direct buffers. */
     private final boolean directBuf;
 
-    /** Index to select which thread will serve next socket channel. Using 
round-robin balancing. */
+    /** Index to select which thread will serve next in socket channel. Using 
round-robin balancing. */
     @GridToStringExclude
-    private int balanceIdx;
+    private final AtomicInteger readBalanceIdx = new AtomicInteger();
+
+    /** Index to select which thread will serve next out socket channel. Using 
round-robin balancing. */
+    @GridToStringExclude
+    private final AtomicInteger writeBalanceIdx = new AtomicInteger(1);
 
     /** Tcp no delay flag. */
     private final boolean tcpNoDelay;
@@ -683,12 +688,12 @@ public class GridNioServer<T> {
      * @param req Request to balance.
      */
     private synchronized void offerBalanced(NioOperationFuture req) {
-        clientWorkers.get(balanceIdx).offer(req);
+        assert req.operation() == NioOperation.REGISTER : req;
+        assert req.socketChannel() != null : req;
 
-        balanceIdx++;
+        int balanceIdx = req.accepted() ? readBalanceIdx.getAndAdd(2) : 
writeBalanceIdx.getAndAdd(2);
 
-        if (balanceIdx == clientWorkers.size())
-            balanceIdx = 0;
+        clientWorkers.get(balanceIdx & (clientWorkers.size() - 1)).offer(req);
     }
 
     /** {@inheritDoc} */

Reply via email to