如果Netty channel isWritable return false,数据会排到哪里 [英] Where will the data been queued if Netty channel isWritable return false

查看:174
本文介绍了如果Netty channel isWritable return false,数据会排到哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Netty api,它显示如果 isWritable 返回 false,请求将排队.我能知道请求在哪里排队吗?在什么情况下,队列可能已满并导致 OOM 问题?

From the Netty api, it shows the request will be queued if isWritable return false. Could I know where will the request be queued? In what case, the queue could be full and cause OOM issue?

以下是isWritable()的文档

Following is the document for isWritable()

当且仅当 I/O 线程将立即执行请求的写操作时返回真.此方法返回 false 时发出的任何写入请求都会排队,直到 I/O 线程准备好处理排队的写入请求.

Returns true if and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returns false are queued until the I/O thread is ready to process the queued write requests.

https://netty.io/4.1/api/io/netty/channel/Channel.html#isWritable--

推荐答案

它将在由 netty 维护的内部缓冲区中排队.为了避免系统出现 OOM,您必须覆盖 ChannelInboundHandler 的方法 channelWritabilityChanged 并进行背压处理.

It will be queued in an internal buffer maintained by netty. To avoid the system from going OOM you will have to override the method channelWritabilityChanged of the ChannelInboundHandler and do back pressure handling.

在这里,您可以使用 channelautoread 配置来减慢读取入站数据的速度,并按照 这里.或者,如果您在不同的线程上编写代码,则可能需要阻止该线程.

Here you can slow down the reading of the inbound data by using the autoread config of the channel and manually read the request as described here. Or if you are writing on a different thread you might need to block that thread.

这篇关于如果Netty channel isWritable return false,数据会排到哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆