开发者

What is "Sim blocking" (seen in tomcat doc)?

I saw the following description in the official tomcat configuration documentation (APR connector description omitted):

             Java Blocking Connector       Java Nio Blocking Connector
Classname         Http11Protocol                  Http11NioProtocol   
Tomcat Version   3.x 4.x 5.x 6.x                       6.x            
Support Polling         NO                             YES            
Polling Size           N/A                   Unlimited - Restricted by mem
Read HTTP Requ开发者_运维技巧est     Blocking                     Non Blocking
Read HTTP Body        Blocking                     Sim Blocking
Write HTTP Response   Blocking                     Sim Blocking
SSL Support           Java SSL                     Java SSL
SSL Handshake         Blocking                     Non blocking
Max Connections       maxThreads                   See polling size

What does "Sim Blocking" mean?


According to Filip Hanik, a Tomcat committer, it means "simulated blocking". (Reference: Tomcat User Mailing list post)


Just a guess, but it could stand for simulated blocking, meaning a blocking api wrapped around the underlying non-blocking nio api.


SourceCode: https://github.com/apache/tomcat/blob/8.5.x/java/org/apache/tomcat/util/net/NioEndpoint.java

       /**
         * NioEndpoint.NioSocketWrapper.fillReadBuffer() 用于直接读取内容到 传入的任意 ByteBuffer 中
         *
         * @param block  是否阻塞读
         * @param buffer 待接收数据的buffer
         * @return 读取到的字节数
         * @throws IOException
         */
        private int fillReadBuffer(boolean block, ByteBuffer buffer) throws IOException {
            int n = 0;
            if (getSocket() == NioChannel.CLOSED_NIO_CHANNEL) {
                throw new ClosedChannelException();
            }
            if (block) { // if no readListener. block variable is true.
                long timeout = getReadTimeout();
                long startNanos = 0;
                do {
                    if (startNanos > 0) {
                        long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
                        if (elapsedMillis == 0) {
                            elapsedMillis = 1;
                        }
                        timeout -= elapsedMillis;
                        if (timeout <= 0) {
                            throw new SocketTimeoutException();
                        }
                    }
                    n = getSocket().read(buffer);
                    if (n == -1) {
                        throw new EOFException();
                    } else if (n == 0) {
                        if (!readBlocking) {
                            readBlocking = true;
                            registerReadInterest(); // <=============== (向关联的Poller)注册读事件.
                        }
                        synchronized (readLock) {
                            if (readBlocking) {
                                try {
                                    if (timeout > 0) {
                                        startNanos = System.nanoTime();
                                        readLock.wait(timeout); // block itself here < ===================
                                    } else {
                                        readLock.wait();
                                    }
                                } catch (InterruptedException e) {
                                    // Continue
                                }
                            }
                        }
                    }
                } while (n == 0); // TLS needs to loop as reading zero application bytes is possible
            } else {
                n = getSocket().read(buffer);
                if (n == -1) {
                    throw new EOFException();
                }
            }
            return n;
        }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜