Hi all,
First, I wanted to drag attention my library aiofastnet .
If you’re using transport/protocol/streams from asyncio directly or indirectly, it will allow to significantly improve performance of your code especially for TLS connections. The idea is simple: use low level add_reader/add_writer and direct access to OpenSSL functions to re-implement transport/protocol networking and eliminate memory copying and python plumbing as much possible.
I hope some people will find it useful.
Second, while doing aiofastnet, I realized that the asyncio’s design around transport/protocol in general could be somewhat improved:
- Would be nice to have a clear attribute that says if loop is selector or proactor. Or have ABC like AbstractSelectorEventLoop or AbstractProactorEventLoop and derive actual loop from it.
- For AbstractProactorEventLoop specifically, there could be methods like sock_recv_impl, sock_recvinto_impl, etc that should NOT be async, should NOT return a Future, but instead just receive a simple callback and call it immediately when operation is complete. Do not post-pone it with call_soon or anything like that. This will close performance gap between selector and proactor implementations.
- Make transport/protocol implementation re-usable and replaceable. Right now, all 3rdparty loops have to re-implement it. asyncio, uvloop, winloop, have similar code for SelectorTransport and SSLTransport/SSLProtocol, and 99% of it is loop independent. There is no well-defined way to set transport/protocol implementation for the loop, except for monkey patching. Maybe something like asyncio.set_transport_protocol_policy or implementation is possible?
Apologies if these have been already discussed somewhere. I’m eager to hear your thought. Thank you in advance.