Replies: 1 comment 4 replies
-
|
@bdraco is probably best to review. But, if we're happy with it, then it'd need to be an optional speedups dependency and likely used by default when available (not via envvar). |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
Perhaps you would be interested in adding Kernel TLS support and native TLS sendfile to aiohttp through my little library aiofastnet?
This will let aiohttp to serve FileResponses over TLS connections much more efficiently.
TLS in aiofastnet is also just faster than in asyncio and uvloop, because it uses openssl directly and remove a lot of python plumbing.
I did a branch showing how aiofastnet can be possibly used from aiohttp.
tarasko#1
I also added example that will let you to try kTLS and compare it against fallback FileResponse, with or without uvloop.
https://github.com/tarasko/aiohttp/blob/feature/aiofastnet/examples/ktls_static_file.py
On my laptop sending 2GB file over loopback interface is roughly 40% faster with kTLS enabled.
kTLS is available on Linux (and allegedly on FreeBSD, but I haven't tried)
To try it out:
Check that you have more or less recent Linux kernel >=5.16.
Check that your Python _ssl module is loading system libssl and libcrypto. I think this is normally the case unless you use conda which install its own libssl and libcrypto into python environment. They are build on CI server with an old kernel. You can just locate them and soft-link to the system libssl and libcrypto
Check that system openssl is >=3.0.x. The newer the better.
Make a new environment, clone my copy of aiohttp and check out feature/aiofastnet branch.
Run example with debug log level to verify that kTLS will be enable when client connects:
It will create a 2Gb file, which can be downloaded:
You can use curl to download and measure speed:
If kTLS is enabled you will see in the server's log:
Let me know if you're interested, but couldn't make it work. OpenSSL is terrible at explaining why it refuses to enable kTLS, it often doesn't give any clue, just silently refuse to do it. I can help with troubleshooting.
You can also experiment with strace to check what syscalls are being called:
After OpenSSL has enabled kTLS, SSL_sendfile just calls regular
sendfileand let kernel tls module load and encrypt file content:All functional tests of aiohttp pass with aiofastnet, with a couple exceptions, where the test itself is not really functional, but mock some loop/transport methods.
To run the tests in the branch:
Beta Was this translation helpful? Give feedback.
All reactions