Channel.isWritable()

jasons2645 jstevens at pillardata.com
Fri Jun 12 13:30:35 EDT 2009


First off, let me provide a little background on what I am doing.  I have a
server that sends potentially large files (up to 4GB) to clients.  Both the
server and client are using Netty.  Since RAM is limited on both boxes, the
server reads the large file 4K at a time, sending these 4K chunks to the
client, which writes them to disk.



Since the server can read these 4K chunks from the disk much faster than it
can send them over the network, it must have some mechanism to know when the
Netty write buffer for the channel has become 'too full', and then wait for
it to come down in size before attempting to send more data.  Otherwise,
this write buffer will grow too quickly and blow the top off the JVM on the
server.



To accomplish the above, I tried 2 approaches (neither worked):

1) Whenever the server goes to write a 4K chunk to the channel, it waits
until the channel reports true for isWritable.

2) I reflectively got a hold of the channel's current write buffer size
(yes, this is hacky), and whenever the server went to write a 4K chunk to
the channel, it waited until the write buffer size dropped below 64K.



In both of these cases, the server would send data for a while and then
stop.  After further investigation, I discovered that the server had written
more data to the wire than the client had read off the wire.  It was as if
the client needed more chunks before it would notify its ChannelHandler that
a message had arrived.  Sure enough, when I modified approach (1) above so
that the server waited for up to 300ms, then sent the data anyway, the code
worked (although rather slowly, since there are occasional 300ms hiccups).



Is the behavior I've seen a bug?  Or is there something I'm doing wrong /
another mechanism I should be using to accomplish this?  Thanks in advance!
-- 
View this message in context: http://n2.nabble.com/Channel.isWritable%28%29-tp3068932p3068932.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list