<div dir="ltr"><div class="gmail_default"><div class="gmail_default">Twisted Community</div><div class="gmail_default"><br></div><div class="gmail_default"><font face="georgia, serif">Problem: How do you determine the buffer size of a transport, to know how much data is waiting to be transmitted from using transport.write?</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Wait! You're going to say: use the Producer Consumer API ( <a href="http://twistedmatrix.com/documents/current/core/howto/producers.html">http://twistedmatrix.com/documents/current/core/howto/producers.html</a> )</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">To do what: So that instead of using back pressure I can check the buffer and when it's "too big/full" can decide to do something to the transport I am writing to:</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre">    </span>Slow transport handling options:</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">- Buffer to disk instead of memory</font></div><div class="gmail_default"><font face="georgia, serif">- Kill the transport</font></div><div class="gmail_default"><font face="georgia, serif">- Decide to skip sending some data</font></div><div class="gmail_default"><font face="georgia, serif">- Send an error or message to the transport I am writing to</font></div><div class="gmail_default"><font face="georgia, serif">- Reduce the resolution, increase the compression (things like video or audio)</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Why not use back pressure?: Some use-cases and some protocols this doesn't make sense.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre"> </span>Examples:</font></div><div class="gmail_default"><span class="" style="white-space:pre"><font face="georgia, serif"> </font></span></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre">  </span>- You're sending video and if the receiver can't keep up you want to downgrade or upgrade the quality of the video, but if you don't know if you can't tell how much it buffering.</font></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre">        </span>- You're receiving from one connection and then broadcasting what you received to multiple clients and you want to handle it by sending an error to a client that doesn't keep up</font></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre"> </span>- You're sending a real-time protocol and want to skip sending some data that's no longer relevant if the buffer is too slow.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">On a server what are the consequences: </font></div><div class="gmail_default"><font face="georgia, serif"><span class="" style="white-space:pre">   </span>Too much buffering in many transport write buffer can cause a server to fail.  I don't know how to keep track of this to proactively without access to the buffer sizes.  Resolutions can then be to, not accept new connections when memory pressure is too high, kill connections with the weakest/slowest clients or have a protocol that can have client switch connections to new servers when instructed to spread out the load.</font></div><div class="gmail_default"><span class="" style="white-space:pre"><font face="georgia, serif">      </font></span></div><div class="gmail_default"><font face="georgia, serif">1) I would like to hear on how people would solve this sort of problem in Twisted for a server?</font></div><div class="gmail_default"><font face="georgia, serif">2) I would like to hear people opinions on this in general.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Tobias Oberstein - BCC'ed you on this email because you seems to have tackled similar problems (based on the mailing list) and would really love to get your take on this too.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Glyph and Jean-Paul, you're also big on those threads so any opinions you have would be appreciated as well.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Some of my background research </font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://twistedmatrix.com/pipermail/twisted-python/2015-January/029064.html">http://twistedmatrix.com/pipermail/twisted-python/2015-January/029064.html</a></font></div><div class="gmail_default"><font face="georgia, serif">* Later but good in the chain: <a href="http://twistedmatrix.com/pipermail/twisted-python/2015-January/029071.html">http://twistedmatrix.com/pipermail/twisted-python/2015-January/029071.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Twisted receiving buffers swamped?</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Great thread but runs into a tangent for a while and picks up good at the end again discussing producer again and the need for backpressure</font></div><div class="gmail_default"><font face="georgia, serif">  * Other: </font></div><div class="gmail_default"><font face="georgia, serif">    * <a href="http://crossbar.io/">http://crossbar.io/</a></font></div><div class="gmail_default"><font face="georgia, serif">    * <a href="http://tavendo.com/">http://tavendo.com/</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Scenario: "Twisted is reading off the TCP stack from the kernel and buffering in userspace faster than the echo server is pushing out stuff to the TCP stack into the kernel. Hence, no TCP backpressure results, netperf happily sends more and more, and the memory of the Twisted process runs away."</font></div><div class="gmail_default"><font face="georgia, serif">  * Confirmed: Data isn't Buffered in "userspace inside Twisted, and before data is handled by the app in dataReceived."</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="https://twistedmatrix.com/pipermail/twisted-python/2010-September/022900.html">https://twistedmatrix.com/pipermail/twisted-python/2010-September/022900.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * How to cap the buffering size of data to be sent<span class="" style="white-space:pre">    </span>in Protocol class</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Same issue, very short no good info</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="https://twistedmatrix.com/pipermail/twisted-python/2012-March/025416.html">https://twistedmatrix.com/pipermail/twisted-python/2012-March/025416.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Limit on transport.write</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Similar issue, very short no good info, glyph confirms that transport.write buffers everything sent to it.</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="https://twistedmatrix.com/pipermail/twisted-python/2012-February/025215.html">https://twistedmatrix.com/pipermail/twisted-python/2012-February/025215.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * pushing out same message on 100k TCPs</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Interesting discussion but different issue - interesting aside about irc spanning trees for a large broadcasts</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://twistedmatrix.com/pipermail/twisted-python/2008-April/017503.html">http://twistedmatrix.com/pipermail/twisted-python/2008-April/017503.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Question on push/pull producers inter-workings, was : "Is there a simple Producer/Consumer example or tutorial?"</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Related and goes into what a producer is - an explanation of it</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://twistedmatrix.com/pipermail/twisted-python/2004-May/007732.html">http://twistedmatrix.com/pipermail/twisted-python/2004-May/007732.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * When do calls to transport.write() block ?</font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Discusses the right issue, talks about buffer call back if full which would be great (if configurable)</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="https://pythonhosted.org/qbuf/qbuf.twisted_support.MultiBufferer-class.html">https://pythonhosted.org/qbuf/qbuf.twisted_support.MultiBufferer-class.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * <a href="https://launchpad.net/qbuf">https://launchpad.net/qbuf</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: c buffer implementation that's incomplete thought might be promising</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://stackoverflow.com/questions/21821119/twisted-producer-to-many-clients-with-buffer">http://stackoverflow.com/questions/21821119/twisted-producer-to-many-clients-with-buffer</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Was indicating a similar use-case but source doesn't seem to exist on the internet</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://twistedmatrix.com/documents/current/core/howto/producers.html">http://twistedmatrix.com/documents/current/core/howto/producers.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Documentation on Producer and Consumers but only help with a backpressure scenario</font></div><div class="gmail_default"><font face="georgia, serif">* <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-July/015690.html">http://twistedmatrix.com/pipermail/twisted-python/2007-July/015690.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * Summary: Discussion on how producer-consumer API's work and future enhancement no help</font></div><div class="gmail_default"><font face="georgia, serif">* MANY MORE THAT 100% NOT RELEVANT</font></div></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">Steve Morin | Hacker, Entrepreneur, Startup Advisor <div><div><div><span style="font-size:x-small"><a href="http://twitter.com/SteveMorin" target="_blank">twitter.com/SteveMorin</a> | <a href="http://stevemorin.com" target="_blank">stevemorin.com</a></span></div></div></div><div><i>Live the dream start a startup. Make the world ... a better place.</i></div></span></div>
</div>