Julien, I agree. A single thread with one Selector can be optimized for non-blocking I/O to handle a large number of streams simultaneously.
-Chad On May 31, 2012, at 2:55 PM, Julien Vermillard wrote: > Hi, > In mina 2 the event loops are composed of Acceptor/Connector (for > accepting/connecting TCP sessions) and IoProcessor for handling > session read and write events. For each service you need at least one > Acceptor/connector and one IoProcessor, so at least two threads. For a > simple TCP base asynchronous proxy it sould be doable with one thread. > > The IoProcessor for TCP and for UDP are totally differents, the TCP > one select TCP client sockets the UDP one handle read write event > passed by the Acceptor because you have only one socket in a UDP > server. > > Ayway this logic make the code uber complicated, what I propose : > > Two technical event loop construction : > A SelectorProcessor, his work is to select SelectableChannel for IO > event (read, write, accept) and push events to listeners (e.g. > TcpServer for accept events, UdpServer for read events on new > sessions) > A EventProcessor, his work is to process read/write events coming from > SelectorProcessor using session chains with one thread event. > > So we can wired SelectorProcessor and EventProcessor like we want, > from just one SelectorProcessor for a one thread logic for quick > server, to multiple SelectorProcessor pushing event to multiple > EventProcessors. > > I think it'll make the code really simpler, testable with mock and > more modulable. > > Julien
