Created On:  28 March 2011

Problem:

  • Product Name:VisiBroker
  • Platform/OS Version:ALL

Can you explain the difference in the behavior between NIO and blocking IO in VisiBroker?

Resolution:

1. VisiBroker uses blocking IO when the property (vbroker.se.iiop_tp.scm.iiop_tp.manager.type) is set as "Socket".  This is the default value.

When a request is being processed in the server, another worker thread from the pool will be awaken and will be waiting in the on the socket read as seen in the stack below:

"VBJ ThreadPool Worker id=0 se=iiop_tp scm=iiop_tp" daemon prio=6 tid=0x0b9b4008 nid=0x2adc runnable [0x0c45f000..0x0c45f9e8]
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at com.inprise.vbroker.IIOP.Connection.read(Unknown Source)
        at com.inprise.vbroker.GIOP.BaseInputStream.readFromConnection(Unknown Source)
        at com.inprise.vbroker.GIOP.MessageFactory.readMessage(Unknown Source)
        at com.inprise.vbroker.GIOP.GiopConnection.receive_message(Unknown Source)
        at com.inprise.vbroker.IIOP.ProtocolConnection.receive(Unknown Source)
        at com.inprise.vbroker.IIOP.ProtocolConnection.receive_request(Unknown Source)
        at com.inprise.vbroker.IIOP.ServerProtocolAdapter.readMessage(Unknown Source)
        at com.inprise.vbroker.orb.TPDispatcherImpl$TPDispatcher.run(Unknown Source)
        at com.inprise.vbroker.orb.ThreadPool$PoolWorker.run(Unknown Source)

  
2. VisiBroker uses Java Non-blocking IO (NIO) package when the above property is set as "Socket_nio".

A thread is awaken when data is available to read or write to the connection.  The Java NIO library has a class "Selector" to support the poll API of the OS from Java applications. The poll() call returns a list of descriptors which are ready to read/write.  Java's Selector.select() API is the java version of poll() API.

The stack trace of the SocketListener waiting on the poll() api is shown below:

"SocketNIOListener se=iiop_tp scm=iiop_tp" (TID:0x21854900, sys_thread_t:0x2177E464, state:R, native ID:0x01B600B1) prio=5
at sun/nio/ch/PollArrayWrapper.poll0(Native Method)
at sun/nio/ch/PollArrayWrapper.poll(PollArrayWrapper.java:144(Compiled Code))
at sun/nio/ch/PollSelectorImpl.doSelect(PollSelectorImpl.java:117(Compiled Code))
at sun/nio/ch/SelectorImpl.lockAndDoSelect(SelectorImpl.java:99(Compiled Code))
at sun/nio/ch/SelectorImpl.select(SelectorImpl.java:110)
at com/inprise/vbroker/orb/SocketSCMnio$ListenerThread.run(Bytecode PC:57)
at java/lang/Thread.run(Thread.java:811)

VisiBroker for C also uses the poll() function call.