ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [49/50] [abbrv] ignite git commit: io
Date Mon, 10 Oct 2016 12:13:45 GMT
io


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

Branch: refs/heads/ignite-gg-8-io2-selNow
Commit: 47ec985f5ab5734609f46ff0c9326bbd4797fef8
Parents: f6f20e2
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Oct 10 11:07:34 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Oct 10 11:58:11 2016 +0300

----------------------------------------------------------------------
 .../managers/communication/GridIoManager.java   |  2 +-
 .../ignite/internal/util/nio/GridNioServer.java | 63 ++++++++++++++++----
 2 files changed, 53 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/47ec985f/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index 7c8d313..c79c7ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -975,7 +975,7 @@ public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializa
         if (msg.topicOrdinal() == TOPIC_IO_TEST.ordinal()) {
             IgniteIoTestMessage msg0 = (IgniteIoTestMessage)msg.message();
 
-            if (!msg0.request()) {
+            if (msg0.processFromNioThread()) {
                 c.run();
 
                 return;

http://git-wip-us.apache.org/repos/asf/ignite/blob/47ec985f/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 8006a2c..2e8a295 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
@@ -497,9 +497,8 @@ public class GridNioServer<T> {
             }
         }
         else if (!ses.procWrite.get() && ses.procWrite.compareAndSet(false, true))
{
-            ses.worker.offer((SessionChangeRequest) fut);
-
-            ses.wakeupCnt.increment();
+            if (ses.worker.offer((SessionChangeRequest)fut))
+                ses.wakeupCnt.increment();
         }
 
         if (msgQueueLsnr != null)
@@ -1410,7 +1409,9 @@ public class GridNioServer<T> {
         /** Worker index. */
         private final int idx;
 
-        public final boolean wakeup;
+        private final boolean writer;
+
+        private boolean selNow;
 
         /**
          * @param idx Index of this worker in server's array.
@@ -1427,7 +1428,7 @@ public class GridNioServer<T> {
 
             this.idx = idx;
 
-            wakeup = idx % 2 == 0;
+            writer = idx % 2 == 1;
         }
 
         /** {@inheritDoc} */
@@ -1511,12 +1512,20 @@ public class GridNioServer<T> {
          *
          * @param req Change request.
          */
-        private void offer(SessionChangeRequest req) {
+        private boolean offer(SessionChangeRequest req) {
             changeReqs.offer(req);
 
-            selector.wakeup();
+            if (select) {
+                selector.wakeup();
+
+                return true;
+            }
+
+            return false;
         }
 
+        private volatile boolean select;
+
         /**
          * Processes read and write events and registration requests.
          *
@@ -1611,8 +1620,34 @@ public class GridNioServer<T> {
                         }
                     }
 
-                    // Wake up every 2 seconds to check if closed.
-                    if (selector.select(2000) > 0) {
+                    int cnt = 0;
+
+                    if (writer && selNow) {
+                        long end = U.currentTimeMillis() + 100;
+
+                        do  {
+                            cnt = selector.selectNow();
+                        }
+                        while (cnt == 0 && U.currentTimeMillis() < end &&
changeReqs.isEmpty());
+                    }
+
+                    if (cnt == 0) {
+                        selNow = false;
+
+                        select = true;
+
+                        try {
+                            if (changeReqs.isEmpty()) {
+                                // Wake up every 2 seconds to check if closed.
+                                cnt = selector.select(2000);
+                            }
+                        }
+                        finally {
+                            select = false;
+                        }
+                    }
+
+                    if (cnt > 0) {
                         // Walk through the ready keys collection and process network events.
                         if (selectedKeys == null)
                             processSelectedKeys(selector.selectedKeys());
@@ -1773,8 +1808,11 @@ public class GridNioServer<T> {
                     if (key.isReadable())
                         processRead(key);
 
-                    if (key.isValid() && key.isWritable())
+                    if (key.isValid() && key.isWritable()) {
                         processWrite(key);
+
+                        selNow = true;
+                    }
                 }
                 catch (ClosedByInterruptException e) {
                     // This exception will be handled in bodyInternal() method.
@@ -1818,8 +1856,11 @@ public class GridNioServer<T> {
                     if (key.isReadable())
                         processRead(key);
 
-                    if (key.isValid() && key.isWritable())
+                    if (key.isValid() && key.isWritable()) {
                         processWrite(key);
+
+                        selNow = true;
+                    }
                 }
                 catch (ClosedByInterruptException e) {
                     // This exception will be handled in bodyInternal() method.


Mime
View raw message