Thanks Lee,<div><br></div><div>I am using TCP NIO and the servers will be in different host environments across regions.</div><div>I was looking into collectd to gather bandwidth throughput of the server and compare with the Netty app throughput to decide on the routing logic.</div>
<div>But that didn&#39;t seem like a proper solution because of Netty app hitting OOM in case Channel.isWritable becomes false.</div><div><br></div><div>As you explained, if taking some kind of average across Channels writable status, can give a close indication on congestion, then it will be a good solution.</div>
<div>I will read more about this in api docs and try it out. Hope it gives a reliable result.</div><div><br></div><div>One more question, Is there an api to get the global throughput statistics?</div><div><br>George</div>
<div><br><div class="gmail_quote">On Wed, Jul 27, 2011 at 12:35 PM, ljohnston <span dir="ltr">&lt;<a href="mailto:johnstlr@yahoo.co.uk">johnstlr@yahoo.co.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi George<br>
<br>
You can&#39;t tell directly if a network is congested or not. As Mike has noted<br>
TCP uses various algorithms to decide if a network is congested or not but<br>
they basically come down to whether a series of packets sent at a given time<br>
are acknowledged within a certain time window. If they are then there&#39;s no<br>
congestion, if they&#39;re not then there&#39;s congestion.<br>
<br>
You don&#39;t state whether you are streaming over TCP or UDP. It&#39;s important<br>
because with TCP it is possible to infer whether there is congestion. With<br>
UDP it depends on whether your protocol has some form of congestion<br>
avoidance. If it doesn&#39;t then you&#39;ll send UDP packets onto the network at<br>
the top speed the server can manage only for them to be dropped at the first<br>
congested router. Without some form of congestion avoidance you can&#39;t detect<br>
this unless the client tells you it&#39;s not receiving anything.<br>
<br>
Assuming you are using TCP, and that you are using NIO sockets, then there<br>
is a way you can potentially detect congestion on a single connection. NIO<br>
sockets have a writeBufferhighWaterMark and a writeBufferLowWaterMark.<br>
Normally Netty forwards your data to the network stack send buffer<br>
immediately. If Netty is unable to do so, because the send buffer is full,<br>
then these two parameters specify how much data Netty will queue before<br>
setting Channel.isWritable to false.<br>
<br>
Once the network stack send buffer drains, and Netty is able to reduce it&#39;s<br>
queue size below writeBufferLowWaterMark, Netty will raise an event stating<br>
that the channel is again writable.<br>
<br>
By checking if the channel is writable after is call to Channel.write, and<br>
capturing the channelInterestChanged event, you can probably infer whether a<br>
channel is managing to process your traffic in a timely manner. If it isn&#39;t,<br>
and you see the same behaviour on other channels, then you can probably<br>
infer network congestion.<br>
<br>
You can tweak the network stack send buffer and Netty<br>
writeBufferHighWaterMark sizes to find the levels which allow you to detect<br>
congestion in reasonable time.<br>
<br>
One final thought, I assume the server you will redirect the client to is on<br>
a completely different network which doesn&#39;t share common links with the<br>
congested network. Otherwise the redirect might not help.<br>
<br>
Cheers<br>
Lee<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://netty-forums-and-mailing-lists.685743.n2.nabble.com/How-to-host-a-high-performing-Netty-App-in-a-fluctuating-network-environment-tp6623821p6627045.html" target="_blank">http://netty-forums-and-mailing-lists.685743.n2.nabble.com/How-to-host-a-high-performing-Netty-App-in-a-fluctuating-network-environment-tp6623821p6627045.html</a><br>

</font><div><div></div><div class="h5">Sent from the Netty User Group mailing list archive at Nabble.com.<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
</div></div></blockquote></div><br>
</div>