<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Anyone know h<span style="font-size:12.8px">ow do you determine the buffer size of a transport, to know how much data is waiting to be transmitted from using transport.write?</span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.8px"><br></span></div><div class="gmail_default" style="font-family:georgia,serif"><span style="font-size:12.8px">Or how you would go about adding that ability to a reactor/transport?</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 17, 2016 at 3:43 PM, Steve Morin <span dir="ltr"><<a href="mailto:steve.morin@gmail.com" target="_blank">steve.morin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">http://twistedmatrix.com/<wbr>documents/current/core/howto/<wbr>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 style="white-space:pre-wrap">     </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 style="white-space:pre-wrap">       </span>Examples:</font></div><div class="gmail_default"><span style="white-space:pre-wrap"><font face="georgia, serif">       </font></span></div><div class="gmail_default"><font face="georgia, serif"><span style="white-space:pre-wrap">        </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 style="white-space:pre-wrap">      </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 style="white-space:pre-wrap">       </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"><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" target="_blank">http://twistedmatrix.com/<wbr>pipermail/twisted-python/2015-<wbr>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" target="_blank">http://twistedmatrix.com/<wbr>pipermail/twisted-python/2015-<wbr>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/" target="_blank">http://crossbar.io/</a></font></div><div class="gmail_default"><font face="georgia, serif">    * <a href="http://tavendo.com/" target="_blank">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" target="_blank">https://twistedmatrix.com/<wbr>pipermail/twisted-python/2010-<wbr>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 style="white-space:pre-wrap">      </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" target="_blank">https://twistedmatrix.com/<wbr>pipermail/twisted-python/2012-<wbr>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" target="_blank">https://twistedmatrix.com/<wbr>pipermail/twisted-python/2012-<wbr>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" target="_blank">http://twistedmatrix.com/<wbr>pipermail/twisted-python/2008-<wbr>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" target="_blank">http://twistedmatrix.com/<wbr>pipermail/twisted-python/2004-<wbr>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" target="_blank">https://pythonhosted.org/qbuf/<wbr>qbuf.twisted_support.<wbr>MultiBufferer-class.html</a></font></div><div class="gmail_default"><font face="georgia, serif">  * <a href="https://launchpad.net/qbuf" target="_blank">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" target="_blank">http://stackoverflow.com/<wbr>questions/21821119/twisted-<wbr>producer-to-many-clients-with-<wbr>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" target="_blank">http://twistedmatrix.com/<wbr>documents/current/core/howto/<wbr>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" target="_blank">http://twistedmatrix.com/<wbr>pipermail/twisted-python/2007-<wbr>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><span class="HOEnZb"><font color="#888888"><br clear="all"><div><br></div>-- <br><div 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>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><b style="font-family:Calibri,sans-serif;font-size:14.6666669845581px"><span style="font-size:10pt;font-family:'Century Gothic',sans-serif;color:black">Steve Morin | Managing Partner - CTO</span></b><br style="font-size:12.8000001907349px"><br></div><div dir="ltr"><p style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><b><span style="font-size:10pt;font-family:'Century Gothic',sans-serif;color:black">Nvent</span></b></p><p style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:8pt;font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)">O </span><span style="color:rgb(5,99,193);font-size:8pt;font-family:'Century Gothic',sans-serif"><a href="tel:800-407-1156;803" target="_blank">800-407-1156 ext 803</a> </span><span style="font-size:8pt;font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)">| M </span><a href="tel:347-453-5579" style="color:rgb(17,85,204)" target="_blank"><span style="font-size:8pt;font-family:'Century Gothic',sans-serif;color:rgb(5,99,193)">347-453-5579</span></a><span style="font-size:8pt;font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)"> </span></p><p style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span style="color:rgb(5,99,193);font-size:9pt;font-family:'Century Gothic',sans-serif"><a href="mailto:smorin@nventdata.com" style="color:rgb(17,85,204)" target="_blank">smorin@nventdata.com </a></span></p></div><div dir="ltr"><br style="font-size:12.8000001907349px"><b style="font-family:Calibri,sans-serif;font-size:14.6666669845581px"><span style="font-size:10pt;font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)">Enabling the Data Driven Enterprise</span></b><br></div></div><div><b style="font-family:Calibri,sans-serif"><span style="font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)"><font size="1">(Ask us how we can setup scalable open source realtime billion+ event/data collection/analytics infrastructure in weeks)</font></span></b></div><div><b style="font-family:Calibri,sans-serif"><span style="font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)"><font size="1"><br></font></span></b></div><div><span style="font-size:12.8000001907349px;font-family:Calibri,sans-serif"><span style="font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)"><font size="1">Service Areas: Management & Strategy Consulting | Data Engineering | Data Science & Visualization </font></span></span><font size="1"><br></font><b style="font-family:Calibri,sans-serif"><span style="font-family:'Century Gothic',sans-serif;color:rgb(31,73,125)"><font size="1"><br></font></span></b></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>