[Async-sig] APIs for high-bandwidth large I/O?

Antoine Pitrou antoine at python.org
Mon Oct 23 08:35:35 EDT 2017


Hi Ludovic,

Le 22/10/2017 à 18:51, Ludovic Gasc a écrit :
> 
> To my understanding, some AsyncIO libraries, like aiohttp, don't 
> use Streams API of AsyncIO and implement a specific implementation, 
> especially to have a full control on the buffers: based on the 
> information provided inside the protocol, you are able to know if a 
> small payload or a big payload will arrive on the wire, like 
> Content-Length header with HTTP.
> 
> My question is: Do you think it's possible to have a simple API to fit 
> at the same time small payloads and big payloads, without impacts on 
> efficiency for all use cases ?

On the write side: I think it's always possible, as my PR for Tornado 
shows (*).  You "just" have to implement a smart buffer management scheme.

(*) https://github.com/tornadoweb/tornado/pull/2169

On the read side: you need a readinto()-like API for large buffers. 
Small buffers can still use a read()-like API for convenience.  That 
means a bit of complication to switch from one mode to the other 
internally, but it looks doable.

On the topic of asyncio, however, asyncio Streams are currently layered 
over the Transport / Protocol abstraction, and the data_received() 
paradigm means data is *already* copied at least once when read from the 
socket to a bytes object whose length isn't controlled by the 
application, so it's a lot battle unless Streams are reimplemented 
differently.

Regards

Antoine.



More information about the Async-sig mailing list