-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASGI support? #2902
Comments
has any discussion about ASGI in Python community? |
I recall #2035 Still don't see strong reasons for new code/standard maintenance burden. |
Another question is performance. |
@andrewgodwin confirmed, that ASGI 2 is stable. |
What is the point of ASGI? I understand reasons for wsgi, especially regarding time when it was introduced. But asgi seems like just maintenance burden for framework developers |
Agree spending time on asgi would seem like a waist of time given aiohttp has/is a robust http server itself. Why not use http as the protocol to connect components rather than conceiving of a whole new spec.? Genuine question, I'm not saying there isn't a case for asgi, I just don't see what it is. |
From my perspective, it is because WSGI's abstraction is useful but not good with long-running requests (long poll/websockets), which is why it's basically just WSGI-with-async these days, albeit with all the unicode edge cases tidied up and more than just a request event. Much like when WSGI was first introduced, there's no real reason for any single server to support it - as you said, you already have a good server and application abstraction - but it's that it allows frameworks and servers to be swapped out rather than being tied to each other, which is why I'm pushing it mostly from the framework side of things. |
If both, aiohttp and for example Sanic would support ASGI, I could run my Sanic app on aiohttp server. If Gunicorn would support ASGI, then I could run my aiohttp app on Gunicorn server. If there would be mod_asgi for Apache, then I could run aiohttp ap on mod_asgi. ASGI is needed for the same purposes as WSGI. WSGI does not support and can't support WebSockets, while ASGI can support both, HTTP and WebSockets. Also ASGI integrates well with asyncio. For example you can easily implement streaming, without blocking other requests. |
does anyone care about running sanic app in aiohttp server? is this what users miss at the moment? or it is just idea of infinite flexibility of everything |
@fafhrd91 I think it is more about the idea of infinite flexibility of everything. 🙂 |
I am not against it :) |
It could be developed as a separated project - a bridge between aiohttp and ASGI. Take an app and create simulated ASGI interfaces or vice versa. |
http-asgi-http? Sounds like a mess to me. |
@samuelcolvin for the sake of infinite flexibility you should embrace it :) |
Humm, ok. 🙃 |
I cannot buy the idea of "more work for sake of flexibility" without other visible benefits. |
Now you can run both sanic and aiohttp (and any other asyncio-compatible) servers in the single process, every service on own tcp port. |
Benefits are exactly the same as with WSGI. Currently, while ASGI is not yet adopted by many frameworks and servers, there is no benefit for aiohttp, it is the other way around, ASGI would benefit from aiohttp if aiohttp would be an early adopter and would help to understand if ASGI is good enough and can become a PEP, as a successor to WSGI. But if ASGI will be adopted by many frameworks and servers, aiohttp, without ASGI support would be simply out of game, because no one would want to use a web framework, that can only work with it's own build-in server. And no one would want to use an async HTTP/WebSockets server, that can only be used with it's own build in web framework. But of course if you don't care about standards, and don't see ASGI benefits, then let's close the conversation. |
ASGI is not a standard. |
@sirex WSGI is invented when FastCGI is still heavily used, so it is invented to make web apps be compatible to both FastCGI and more advanced technologies. Asyncio is already an advanced technology. And currently there is no way to let the asyncio interfaces work with legacy servers. |
I'm not sure what you mean by
|
To everyone who keeps asking for ASGI support: please don't bug people about adding it like this. If it gets more adoption, and thus more people willing to work on it, maybe the picture will change, but demanding features from a project that brings them nothing is not great (I would do the same if you asked me for something random on Channels). The first step for anything like this is writing a compatibility shim that would present it as an aiohttp application - that's something that can be done outside of either of our projects (channels or aiohttp) and then released separately. If someone is really keen enough to want to work on that, let me know and I would be happy to advise. |
@andrewgodwin thanks for understanding. |
@samuelcolvin I mean a thread-based web server cannot drive an asyncio interface (like ASGI, an interface is some method which is called by the web server). Gunicorn and uwsgi replaces their workers to support them. Reverse proxies need a separated HTTP server. They do not work like WSGI which only needs a simple wrapper. |
I've started working on an example ASGI adapter for aiohttp based on the work in #2035 (updated for the current ASGI specification). It can be viewed in the example app here: https://github.com/erm/asgi-examples/ |
@asvetlov hope you meant if users of aiohttp can win? :) Here's one major reason - the more common layers would we have - the less fragmented people effords can be. Imagine that maintainers of japronto or vibora would spent time on writing some underlying layer, rather than build whole framework. The layer that can be used by aiohttp, sanic, apistar, maybe even django users. So here's win-win: their projects would get much more attention and aiohttp users would get benefits (speedup in this case) just for free. One more reason - common services / middlewares - not sure how important is it, haven't seen much of them in WSGI world. But I'm here for another reason, just read your (@asvetlov) post on "Architectural problems of Sanic framework". Do you see any problems with asgi approach? |
I very doubt if ASGI is a useful abstraction. Common services / middlewares doesn't exist in WSGI world, why they will appear in ASGI? Regarding to flow control in ASGI -- I didn't dig too deep. Perhaps it is fine, don't know. |
Why not? Here's already at least two ASGI servers (uvicorn and daphne). And couple of frameworks (apistar looks pretty mature) on top of them.
The question is how big is it, just tested on my laptop simple hello world:
The first three - are ASGI frameworks. About viobra, agreed it's barely would use ASGI. But all the other frameworks are showing comparable speed, why do you think that dicts / lists layer will slowdown aiohttp or sanic any significantly? |
Helo world example doesn’t matter. All modern python frameworks uses c-optimized extensions for basic operations. But if you add actual business logic written in python, there would be no difference. Reusable wsgii middleware are magical creatures. I guess it would be the same with asgi |
What world be better than hello-world If we're measuring dicts-lists-layer overhead? |
I have different numbers for aiohttp and sanic on my laptop :) You are comparing apples with oranges. For example aiohttp uses multidict library for HTTP headers, uvicorn operates on list of pairs, apistar uses another structure. A part of apistar performance degradation in comparison with uvicorn itself is headers conversion. |
I don’t think performance matter. I think asgi does not matter in 2018 in general. Usability and complexity matters. Python is not very good choice for high performance system in any case. |
Could you tell a few words about this when you have a minute? Why is it bad and what's the better option? Some lazy loaded structures? |
I've found ASGI to be a very useful abstraction for development at the application level, much more than alternatives. I have generally been less concerned with performance and "hello world" benchmark hype that tend to dominate these discussions - which isn't to say ASGI servers and applications are not performant.
There are common middlewares that exist for WSGI, though I'd say ASGI presents an opportunity to achieve a reusable middleware ecosystem in a way that WSGI did not. Regardless, ASGI is not WSGI.
Correct, but this is a particular framework implementation unrelated to the WSGI specification itself and is even less related to ASGI discussion. The composability of ASGI applications is much more flexible than WSGI for the purpose of creating framework-independent middleware. It is much easier to reuse ASGI applications across multiple framework implementations. An example of this would be how Django Channels middlewares can easily be reused with an ASGI library such as Starlette with no complications. |
@ERM how much useful middlewares you can imagine outside of application context? |
@imbolc Hard for me to say, I referenced the application-level in particular because that is where I am most familiar, but it looks like Uvicorn now provides some middlewares that could help answer that question. cc @tomchristie may be able to speak to this better than I. Also, in regards to my previous comment, I would like to make clear my intention is only to present an individual perspective on ASGI to assist in evaluating it as a specification. If this project would not find it useful to support then it should do what is in the best interest of its maintainers/users - ASGI is just an option to pool developer knowledge and effort and help facilitate greater cooperation across Python frameworks (difficult to demonstrate currently, but things are progressing). |
Examples would be:
There are also other sorts of composition it allows, eg. HTTP or WebSocket testing libraries that plug into any ASGI application. Being able to switch out different servers means it's possible to isolate thorny issues to either being an application issue or a server issue. Plus if even faster cythonised implementations come along you can just seamlessly start using those. Most critically tho is that it lowers the ecosystem complexity as a whole. There's a single clearly defined interface to work against. I can understand the application framework code in isolation, and be confident that it can run against multiple server implementations. (Or write an async "hello world" application without having to tie myself to an application framework.)
Pretty confident in saying that I believe all three of daphne, uvicorn, and hypercorn deal with flow control in both directions and high/low watermarks, yup.
Starlette is essentially the same set of functionality as sanic or aiohttp. The TechEmpower benchmarks there demonstrate that it runs at least with equal performance characteristics. More context on those results here. Obviously it'd be a pain for |
Thanks, @tomchristie |
There was some work on it here. encode/uvicorn#92 I don't think there's any good answer to that without implementing it and looking at various benchmarks. Main point there would be...
If you mean "could Vibora be an ASGI framework?" Then sure, yes.
Nothing significant, no. There's a little light refinement to some edges of the spec, but more from a point of view of strictly clarifying any under-specified aspects of behavior. |
I still have same opinion as before. There is no need for one more middleware api, end users don’t care until framework does not interfere with their work. I believe this new api is just huge burden on maintainers. For me high performance python is a fantasy, but i don’t do aiohttp/python anymore. In the end it is up to @asvetlov |
In general its probably so, but for io-bound things like web apis I don't see why rust would be any faster. I've recently compared actix with vibora on a few db queries with json serialization and got the same speed. |
The issue is closed, isn't it? |
Just to let you all know that I plan to bring ASGI to the PEP process soon - since we now have three separate implementations - so if you have any concrete concerns, that will be the place to raise them properly, rather than here. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
Currently, most of asyncio based web frameworks embeds http server into the web framework. If http/ws servers would use ASGI standard, then it would be possible to run your app using different http/ws servers.
That is why I think it is important for aiohttp to add ASGI support.
Expected behaviour
I would like to write aiohttp app:
And run it with any ASGI compatible server:
Actual behaviour
ASGI resources
https://github.com/django/asgiref/blob/master/specs/asgi.rst - ASGI specification.
https://github.com/django/asgiref/blob/master/specs/www.rst - ASGI-HTTP and ASGI-WebSocket protocol specifications.
Example ASGI app:
The text was updated successfully, but these errors were encountered: