Description
When running a python ASGI app with uvicorn, you have the option to install uvicorn with uvloop, which is then used to speed up the async event loop.
It appears that this code here is all they need for this:
https://github.com/encode/uvicorn/blob/f39933c8501dd6bc2e8e0f5be45819d3ba2caad0/uvicorn/loops/uvloop.py
If uvloop is installed, uvloop_setup
is called and then the event loop is just faster.
When I realized that nginx unit uses the actual asyncio python library (although from C code), I tried to merely copy-paste uvloop_setup
into my app and execute the function on the module level (having installed uvloop, of course). I could see a significant speed-up, same as I do for uvicorn with uvloop. (Requests took like 0.3-0.5 ms less time, which represents a significant part of the overhead.)
To me, it seems like it could possibly be very easy to implement this for unit; it seems like you can just do the same thing that uvicorn does.