0
votes

We have a Netty client/server based upon 4.x

The client will establish a main channel to the server and communicate back and forth on this single connection.

I would like to understand better the usage of the NioEventLoopGroup threads from a Client perspective.

My setup has very basic pipeline. SSLHandler, Encoder, Decoder, MessageHandler

Client: I originally thought the thread was used to process incoming data and outgoing data through the pipeline. However I forced my client to only 1 thread and added a sleep within the channelRead after I submit to an executor service(separate thread) to process the incoming message instead of doing so within the channelRead. That external executor job when its done will write data as a reply to the same channel the data came in on. The server doesn't get the reply until after the sleep has finished which is what I expected. However I then increased the client thread to 2. Ran the same test and server still didn't get a reply until after the 30 seconds. To verify I added system outs in the job after it wrote the reply to the channel which was output prior to even sleeping. I expected the second thread to kick in and process the outgoing reply from the job. So it seems like one client thread is used for a given connection/channel. Is this accurate?

1

1 Answers

1
votes

What you are seeing is expected. Each Channel is "bound" to one EventLoop which is bound to exact one Thread. So it does not matter how many EventLoops you have, one Channel is only handles by the same EventLoop the whole life-time