▲ | PaulHoule 2 days ago | |||||||||||||||||||||||||||||||
I went through a phase of writing asyncio servers for my side projects. Probably the most fun I had was writing things that were responsive in complex ways, such as a websockets server that was also listening on message queues or on a TCP connection to a Denon HEOS music player. Eventually I wrote an "image sorter" that I found was hanging up when the browser was trying to download images in parallel, the image serving should not have been CPU bound, I was even using sendfile(), but I think other requests would hold up the CPU and would be block the tiny amount of CPU needed to set up that sendfile. So I switched from aiohttp to the flask API and serve with either Flask or Gunicorn, I even front it with Microsoft IIS or nginx to handle the images so Python doesn't have to. It is a minor hassle because I develop on Windows so I have to run Gunicorn inside WSL2 but it works great and I don't have to think about server performance anymore. | ||||||||||||||||||||||||||||||||
▲ | tdumitrescu 2 days ago | parent | next [-] | |||||||||||||||||||||||||||||||
That's the main problem with evented servers in general isn't it? If any one of your workloads is cpu-intensive, it has the potential to block the serving of everything else on the same thread, so requests that should always be snappy can end up taking randomly long times in practice. Basically if you have any cpu-heavy work, it shouldn't go in that same server. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
▲ | Townley 2 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||
It’s heartening that there are people who find the problem you described “fun” Writing a FastAPI websocket that reads from a redis pubsub is a documentation-less flailfest |