简体   繁体   中英

Netty Connection Pooling

Netty Connection Pool

I would like to know which options or how to implement a client connection pool in netty.

I have not implemented this, so this is just some educated guess-work, but I would consider combining the following:

The generic object pooling would support you in creating a connection cache, with the remote socket address as the key, so you might issue a request like:

pool.borrowObject("www.google.com:80");

Not sure about the channel group, except that it is a good way to issue directives against all the contained channels in one go (eg close()), so it might be useful to have the pool's PooledObjectFactory always insert all it's created channels into a channel group as well. It is self maintaining since the channels are ejected from the group when they close.

Commons Pooling has been super useful for me in many situations, though mostly when I am attempting to pool and reuse expensive-to-create resources. Is this how you view your client connections ?

Update Aug 30, 2017:

The preferred way to do this in Netty 4.x is to use a ChannelPool. Netty 4.0: ChannelPool Netty 4.1: ChannelPool

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM