1
votes

I'm confused for how to deal with lots of connections in netty (3.6.2.FINAL) and keep-alive=true.

For work on a netty client as a server side connector, making http calls to another service, it wants to always keep the connection open for performance (keep-alive=true).

The issue: there is a hard limit for number of open channels, after which the client will hang when attempting to open a channel. Why no exception just hangs? Is this a setting in terms of channel timeout?

I can't seem to understand Netty in terms of overall managing of connections within worker threads:

  • With a blocking write/read client ChannelHandler (http request/response), how do you detect that the connection pool is empty?

  • The handler can receive ChannelEvent(s) but nothing about the overall count available in the connection pool (its very non-deterministic anyway). And if the channel is not open, does it make sense for the handler to initiate opening a new channel given its running in a worker thread?

  • But if the connection pool is exhausted, how do you go and cleanup some idle connections (within the handler)?
1

1 Answers

0
votes

I had to completely rip apart my handler to get the client blocking call to work without hanging. The issue was mostly resolved by not holding onto local channel ref within the handler.

Now we just pass a ConnectionInterface#openConnection() [returns a new ChannelFuture] into the shared custom ChannelHandler#call( ConnectionInterface connectionInterface, HttpRequest request ).

Better to open-channel within the handler call method, and to pass that channel along with checks on its state before channel.write(x), if !channel.isWritable() then recycle the channel (from a new client connection eg. ConnectionInterface#openConnection()) and retry the write. There isn't even a need to close the channel (it gets handled in the pool).

Just ran it with 500 threads / 5000 requests and it succeeds fine.