The http.client HTTPConnection._send_output method has an optimization for avoiding bad interactions between delayed-ack and the Nagle algorithm:<br><br><a href="http://hg.python.org/cpython/file/f32f67d26035/Lib/http/client.py#l884">http://hg.python.org/cpython/file/f32f67d26035/Lib/http/client.py#l884</a><br>
<br>Unfortunately this interacts rather poorly if the case where the message_body is a bytes instance and is rather large.<br><br>If the message_body is bytes it is appended to the headers, which causes a copy of the data. When message_body is large this duplication of data can cause a significant spike in memory usage.<br>
<br>(In my particular case I was uploading a 200MB file to 30 hosts at the same leading to memory spikes over 6GB.<br><br>I've solved this by subclassing and removing the optimization, however I'd appreciate thoughts on how this could best be solved in the library itself.<br>
<br>Options I have thought of are:<br><br>1: Have some size threshold on the copy. A little bit too much magic. Unclear what the size threshold should be.<br><br>2: Provide an explicit argument to turn the optimization on/off. This is ugly as it would need to be attached up the call chain to the request method.<br>
<br>3: Provide a property on the HTTPConnection object which enables the optimization or not. Optionally configured as part of __init__.<br><br>4: Add a class level attribute (similar to auto_open, default_port, etc) which controls the optimization.<br>
<br>Be very interested to get some feedback so I can craft the appropriate patch.<br><br>Thanks,<br><br>Benno<br><br><br>