Open tarasko opened 2 months ago
How do you get this perf result? I want to learn about this, how to do perf for my code, thanks for your answer.
How do you get this perf result? I want to learn about this, how to do perf for my code, thanks for your answer.
I have updated description with instruction on how to run perf
Bug report
Bug description:
Event loops like uvloop, asyncio use nonblocking ssl. They typically
when peers are exchanging relatively small messages, SSLObject.read is typically called 2 times . First call returns data, second - throws SSLWantReadError
perf shows that the second call is almost as expensive as the first call because of time spent on constructing new exception object.
Is it possible to optimize exception object creation for the second call?
I tried to avoid the second call by analyzing MemoryBIO.pending and SSLObject.pending values but they can't always reliably tell that we have to wait for more data.
For example, it is possible that incoming MemoryBIO.pending > 0, SSLObject.pending == 0. We call SSLObject.read and it throws because incoming MemoryBIO doesn't have the full ssl frame yet.
Example echo client that replicates internal logic in asyncio/uvloop:
Perf output:
To reproduce you would need some ssl echo server running on localhost 25000 port. After you have started it, run echo client code under perf.
Let it work for 15 seconds and then press Ctrl-C
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux