I would like to use Java Netty to create a TCP server for a large number of persistent connections from a clients. In other words, imaging that there are 1000 client devices out there, and all of them create and maintain a persistent connection to the TCP server. There will be a reasonable amount of traffic (mostly lines of text) that go back and forth across each of these persistent connections. How can I determine the best number of threads to use in the boss and worker groups for NioEventLoopGroup?
My understanding is that when the connection is created, Netty creates a SimpleChannelInboundHandler<String>
object to handle the connection. When the connection is created then the handler channelActive
method is called, and every time it gets a new message from the client, the method messageReceived
gets called (or channelRead0
method in Netty 4.0.24).
Is my understanding correct?
What happens if I have long running code to run in messageReceived - do I need to launch this code in yet another thread (java.util.Thread)?
What happens if my messageReceived method blocks on something or takes a long time to complete? Does that bring Netty to a grinding halt?
Basically I need to write a TCP socket server that can serve a large number of persistent connections as quickly as possible.
NioEventLoopGroup
and on how to use any threads inside the handler?Any help would be greatly appreciated.
How can I determine the best number of threads to use in the boss and worker groups for NioEventLoopGroup?
Don't forget to add -XmsYYYYM and -XmxYYYYM as your VM attributes, because without them you can face the case, when your JVM are not using all cores.
What happens if I have long running code to run in messageReceived - do I need to launch this code in yet another thread (java.util.Thread)?
What happens if my messageReceived method blocks on something or takes a long time to complete?
Does that bring Netty to a grinding halt?