简体   繁体   English

网络连接池

[英]Netty Connection Pooling

Netty Connection Pool 网络连接池

I would like to know which options or how to implement a client connection pool in netty. 我想知道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. 不确定通道组,只是它是一种一次性对所有包含的通道发出指令的好方法(例如close()),因此让池的PooledObjectFactory始终将所有创建的通道插入到一个通道中可能会很有用。频道组也是如此。 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. Commons池在许多情况下对我来说超级有用,尽管多数情况下,当我尝试池化和重用昂贵的创建资源时。 Is this how you view your client connections ? 这是您查看客户连接的方式吗?

Update Aug 30, 2017: 2017年8月30日更新:

The preferred way to do this in Netty 4.x is to use a ChannelPool. 在Netty 4.x中执行此操作的首选方法是使用ChannelPool。 Netty 4.0: ChannelPool Netty 4.1: ChannelPool Netty 4.0: ChannelPool Netty 4.1: ChannelPool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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