etianen / aiohttp-wsgi

WSGI adapter for aiohttp.
https://aiohttp-wsgi.readthedocs.io
BSD 3-Clause "New" or "Revised" License
232 stars 20 forks source link

Serving WSGI app from Python code #20

Closed NicolasLM closed 6 years ago

NicolasLM commented 6 years ago

aiohttp-wsgi has a way to serve WSGI apps from the CLI, but there is no easy way to do it from Python code. By easy I mean with a single function call.

The serve function in __main__ is almost good for this use case, except that it expects args from the CLI.

For inspiration, I really like how waitress does it with waitress.serve.

etianen commented 6 years ago

It's a nice idea. I suspect that it can be done very easily by adapting the functions in main. I don't have time to do it myself right now, but I would review a pull request that added a public aiohttp_wsgi.serve() method, with accompanying documentation.

On 2 February 2018 at 13:00, Nicolas Le Manchet notifications@github.com wrote:

aiohttp-wsgi has a way to serve WSGI apps from the CLI, but there is no easy way to do it from Python code. By easy I mean with a single function call.

The serve function in main is almost good for this use case, except that it expects args from the CLI.

For inspiration, I really like how waitress does it with waitress.serve https://docs.pylonsproject.org/projects/waitress/en/latest/#usage.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/aiohttp-wsgi/issues/20, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCC1dC8D-Xx8bnscAtPmadVgiuvIDks5tQwcIgaJpZM4R3JkG .

etianen commented 6 years ago

Added in 0.8.

https://aiohttp-wsgi.readthedocs.io/en/stable/wsgi.html#aiohttp_wsgi.serve

NicolasLM commented 6 years ago

This is awesome, thank you!

etianen commented 6 years ago

You might have noticed that a lot of the public API for aiohttp-wsgi takes it's inspiration from waitress already. The new serve function, along with the existing CLI, are pretty much drop-in replacements.

I'm not 100% convinced there's any reason to use aiohttp-wsgi over waitress if there's no intention to use any async features. I'd be curious to see a performance comparison of the two servers for a hello world WSGI app. I have no idea which one would be faster!

NicolasLM commented 6 years ago

For me the reason is quite simple: waitress uses Python asyncore which is deprecated and may be removed completely from Python at some point. It also has seen little to no development lately.

By using asyncio you're basically using the blessed asynchronous framework for Python which is a good thing.

I did a small benchmark with wrk and waitress is slightly faster but there is some room for improvement. For instance disabling the aiohttp access log raises a 15% speedup.

keis commented 6 years ago

Cool stuff. We've been using some copy-pasted and glued together bits of the main up until now. Motivation can pretty much be summed up in that we want to run other asyncio tasks in the same process without adding another async concept like threads to the picture