You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/02/12 17:25:31 UTC

[ignite] branch ignite-11299 updated (be19ee9 -> 322c82f)

This is an automated email from the ASF dual-hosted git repository.

ilyak pushed a change to branch ignite-11299
in repository https://gitbox.apache.org/repos/asf/ignite.git.


 discard be19ee9  IGNITE-11299 Avoid busy wait on processWrite during SSL handshake.
     new 322c82f  IGNITE-11299 Avoid busy wait on processWrite during SSL handshake.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (be19ee9)
            \
             N -- N -- N   refs/heads/ignite-11299 (322c82f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ignite/internal/util/nio/GridNioServer.java    | 55 +++++++++-------------
 .../internal/util/nio/ssl/BlockingSslHandler.java  |  5 +-
 2 files changed, 24 insertions(+), 36 deletions(-)


[ignite] 01/01: IGNITE-11299 Avoid busy wait on processWrite during SSL handshake.

Posted by il...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ilyak pushed a commit to branch ignite-11299
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 322c82f68c9712f7e24188d1269d9b9cbc6f777b
Author: Ilya Kasnacheev <il...@gmail.com>
AuthorDate: Tue Feb 12 20:24:50 2019 +0300

    IGNITE-11299 Avoid busy wait on processWrite during SSL handshake.
---
 .../ignite/internal/util/nio/GridNioServer.java    | 65 +++++++++++-----------
 .../internal/util/nio/ssl/BlockingSslHandler.java  |  2 +-
 2 files changed, 32 insertions(+), 35 deletions(-)

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 794c8fc..c1319b4 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
@@ -1041,6 +1041,22 @@ public class GridNioServer<T> {
         clientWorkers.get(balanceIdx).offer(req);
     }
 
+    /**
+     * Stop polling for write availability if write queue is empty.
+     */
+    private void stopPollingForWrite(SelectionKey key, GridSelectorNioSessionImpl ses) {
+        if (ses.procWrite.get()) {
+            ses.procWrite.set(false);
+
+            if (ses.writeQueue().isEmpty()) {
+                if ((key.interestOps() & SelectionKey.OP_WRITE) != 0)
+                    key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
+            }
+            else
+                ses.procWrite.set(true);
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridNioServer.class, this);
@@ -1165,16 +1181,7 @@ public class GridNioServer<T> {
                     req = ses.pollFuture();
 
                     if (req == null) {
-                        if (ses.procWrite.get()) {
-                            ses.procWrite.set(false);
-
-                            if (ses.writeQueue().isEmpty()) {
-                                if ((key.interestOps() & SelectionKey.OP_WRITE) != 0)
-                                    key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
-                            }
-                            else
-                                ses.procWrite.set(true);
-                        }
+                        stopPollingForWrite(key, ses);
 
                         break;
                     }
@@ -1356,10 +1363,14 @@ public class GridNioServer<T> {
             boolean handshakeFinished = sslFilter.lock(ses);
 
             try {
-                writeSslSystem(ses, sockCh);
+                boolean writeFinished = writeSslSystem(ses, sockCh);
+
+                if (!handshakeFinished) {
+                    if (writeFinished)
+                        stopPollingForWrite(key, ses);
 
-                if (!handshakeFinished)
                     return;
+                }
 
                 ByteBuffer sslNetBuf = ses.removeMeta(BUF_META_KEY);
 
@@ -1399,16 +1410,7 @@ public class GridNioServer<T> {
                             req = ses.pollFuture();
 
                             if (req == null && buf.position() == 0) {
-                                if (ses.procWrite.get()) {
-                                    ses.procWrite.set(false);
-
-                                    if (ses.writeQueue().isEmpty()) {
-                                        if ((key.interestOps() & SelectionKey.OP_WRITE) != 0)
-                                            key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
-                                    }
-                                    else
-                                        ses.procWrite.set(true);
-                                }
+                                stopPollingForWrite(key, ses);
 
                                 break;
                             }
@@ -1535,8 +1537,10 @@ public class GridNioServer<T> {
          * @param ses NIO session.
          * @param sockCh Socket channel.
          * @throws IOException If failed.
+         *
+         * @return {@code True} if there's nothing else to write (last buffer is written and queue is empty).
          */
-        private void writeSslSystem(GridSelectorNioSessionImpl ses, WritableByteChannel sockCh)
+        private boolean writeSslSystem(GridSelectorNioSessionImpl ses, WritableByteChannel sockCh)
             throws IOException {
             ConcurrentLinkedQueue<ByteBuffer> queue = ses.meta(BUF_SSL_SYSTEM_META_KEY);
 
@@ -1555,8 +1559,10 @@ public class GridNioServer<T> {
                 if (!buf.hasRemaining())
                     queue.poll();
                 else
-                    break;
+                    return false;
             }
+
+            return true;
         }
 
         /**
@@ -1608,16 +1614,7 @@ public class GridNioServer<T> {
                     req = ses.pollFuture();
 
                     if (req == null && buf.position() == 0) {
-                        if (ses.procWrite.get()) {
-                            ses.procWrite.set(false);
-
-                            if (ses.writeQueue().isEmpty()) {
-                                if ((key.interestOps() & SelectionKey.OP_WRITE) != 0)
-                                    key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
-                            }
-                            else
-                                ses.procWrite.set(true);
-                        }
+                        stopPollingForWrite(key, ses);
 
                         return;
                     }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/ssl/BlockingSslHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/ssl/BlockingSslHandler.java
index 0099c46..dded870 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/ssl/BlockingSslHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/ssl/BlockingSslHandler.java
@@ -511,7 +511,7 @@ public class BlockingSslHandler {
      */
     private void writeNetBuffer() throws IgniteCheckedException {
         try {
-            ch.write(outNetBuf);
+            U.writeFully(ch, outNetBuf);
         }
         catch (IOException e) {
             throw new IgniteCheckedException("Failed to write byte to socket.", e);