问题
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?
Following is the document for isWritable()
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--
回答1:
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.
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.
来源:https://stackoverflow.com/questions/53824955/where-will-the-data-been-queued-if-netty-channel-iswritable-return-false