I originally asked this question on Github 
<https://github.com/netty/netty/issues/5757>:

When reading Netty's codes, I find that Netty's event loop process multiple 
IO events in one loop 
<https://github.com/netty/netty/blob/4.1/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java#L609>,
 
whereas most of tutorials and other framework (e.g. rapidoid 
<https://github.com/rapidoid/rapidoid/blob/6e111421fc03d26db80c80183dc97bca2ab990c4/rapidoid-net/src/main/java/org/rapidoid/net/impl/AbstractEventLoop.java#L63>)
 
only process one IO event in one loop. Could someone elaborate a little bit 
on this design? Or I've missed something and both implementation are 
actually the same? Cheers!

And @normanmaurer <https://github.com/normanmaurer> posted a helpful reply:

@FlyClover <https://github.com/FlyClover> its basically handles all the 
events for each Channel that are present. If you not handle each of the 
events it will cause the select() to not block on the next call as there 
are more events to handle. So at the end you will handle all events in both 
implementations. That said it is kind of wasteful to not directly handle 
all events in the first place as you will do extra select() calls while 
have the same outcome later on.

I've got a further question. In our implementation (on Android), we use 
rapidoid's way of processing events. Say if a simplified event loop looks 
like this:

*while (true) {*
*  selector.select();*
*  Iterator<SelectionKey> iterator = 
socketSelector.selectedKeys().iterator();*
*  while (iterator.hasNext()) {*
*    SelectionKey key = iterator.next();*
*    if (key.isConnectable()) {*

*    } else if (key.isAcceptable()) {*

*    } else if (key.isReadable()) {*

*    } else if (key.isWritable()) {*

*    }*
*    ...*
*  }*
*}*

The problem we come across in this implementation is that if the channel 
has lots of read events and few write events, read will block write. If we 
use Netty's implementation, the problem will be gone. My question is, apart 
from the benefit @normanmaurer <https://github.com/normanmaurer> mentioned 
above, Netty's implementation seems more fair, but why still most of the 
implementations I could find still use the the other style?

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/1515cdd8-25ad-41fd-bedb-a712efefe6fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to