简体   繁体   English

如何使用慢速客户端限制 netty 服务器?

[英]How to throttle netty server with slow client?

In order to prevent OOME in a riemann server when clients do not read ACKs properly, I have implemented some logic to close the channel when it becomes unwritable, under the assumption this is caused by client not reading/ACKing packets quickly enough.为了在客户端没有正确读取 ACK 时防止 riemann 服务器中的OOME ,我实现了一些逻辑以在通道不可写时关闭通道,假设这是由于客户端没有足够快地读取/ACK 数据包造成的。

However, this also closes the channel when sending large-ish query results, probably because the server tries to write the result faster than it can be sent through TCP.但是,这也会在发送大型查询结果时关闭通道,可能是因为服务器尝试写入结果的速度比通过 TCP 发送的速度快。 Out of the top of my head, I would think the best way to handle this situation would be to set some timeout on writing, using a WriteTimeoutHandler .在我的脑海中,我认为处理这种情况的最佳方法是使用WriteTimeoutHandler设置一些写入超时。

Is there some standard pattern known in netty to handle that case? netty 中是否有一些已知的标准模式来处理这种情况?

Basically you would stop writing once Channel.isWritable() returns false and start again once it returns true again.基本上你会在Channel.isWritable()返回 false 后停止写入,并在它再次返回 true 后重新开始。 You can be notified by the update of this by overriding ChannelInboundHandler.channelWritabilityChanged(...) .您可以通过覆盖ChannelInboundHandler.channelWritabilityChanged(...)来收到更新通知。

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

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