Gregory P. Smith <g...@krypto.org> added the comment:

FYI another common socket idiom for this, specifically added for use in old 
HTTP 1.x servers building up responses, is setting and clearing the TCP_CORK 
(Linux) or TCP_NOPUSH (FreeBSD, and maybe macos? [buggy?]) socket option before 
and after the set of send()s you want to be optimally buffered into packets.

A more modern approach (often used with TCP_CORK) is not to build up a single 
buffer at all.  Instead use writev().  os.writev() exists in Python these days. 
 It limits userspace data shuffling in the normal case of everything getting 
written.

Unfortunately... this old http client code and API isn't really setup for that. 
 Everything is required to go through the HTTPConnection.send method.  And the 
send method is not defined to take a list of bytes objects as writev() would 
require.  

So for this code, the patch we want is just the joined bytes or BytesIO. It is 
the simple better change that works everywhere without getting into platform 
specific idioms.

For modern best practices I'd look to the async frameworks instead of this 
older library.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43332>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to