-
Notifications
You must be signed in to change notification settings - Fork 243
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
Curio-Asyncio Bridge (Discussion) #190
Comments
So the problem we are having at the moment using curio is we don't get the massive existing asyncio ecostructure. For example we need a http endpoint for something, we have a very fragile model at the moment that uses falcon and some thread and async magic to compat between them but it breaks and is not good. In an ideal world we could take something like
And boom, we have async http gateway that doesn't hurt either side. But this is all quite hard. I mean it would be killer if curio had some http framework itself, but thats past the point here, until it comes about we are stuck with compat... |
Personally, I feel like the version you've posted isn't much different from running |
The modified version still has the background thread and allows thousands of Curio tasks to submit work simultaneously to the same event loop. So, in that sense, it's quite a different than calling One benefit to packaging this up into a "Loop" object is that it can accomplish the same thing as the |
On asyncio-curio communication, a UniversalQueue could probably be used for this, although it might require some tweaking. I will investigate. |
I've made some changes to the
Coroutines submitted to the loop do not line up in a queue. They all run at once. Total execution time of this code is about 2 seconds on my machine. General thoughts: I think the API should be pretty explicit about what's happening (i.e., this coroutine is running on |
So here is the code working actually flawlessly. The only problem is performance takes a bit of a hit going over universal queue. If the handler doesn't have to interact with the queue it can do roughly 33k requests on my machine, if the handler (like in the example) needs to interact with the queue it does only 3k. Any ideas?
|
The UniversalQueue implementation is not the fastest thing around at the moment. However, there might be some things that can be done to make it much faster (I have some ideas). In a situation where the curio_thingy() does much more work than echoing right away, I'd imagine that the queue overhead would wash out a bit as well. |
But it does work which is grand. I am working on a curio web framework as a personal project but until it is done this will let us use asyncio web frameworks. Thanks for your involvement. |
I just pushed a re-envisioned UniversalQueue implementation. It is much faster. One note: On the above code sample, it's not safe to use a single queue for back-and-forth interaction like that. Two queues should be used--one for each direction. |
Have you used any python 3.6 syntax in this latest set of changes, they are super useful to our project but we are currently stuck on 3.5 would there be a release for this on pip ? |
Not aware of Python 3.6 syntax per-se (in the core) although there are some Python 3.6 features being tested in the test-suite. |
I will say the speedup is substantial. More than 4x faster on a back-and-forth example like you showed above. It's about 8-20x faster on producer-consumer queuing when I tested it. |
PR #188 added some initial support for an curio-asyncio bridge. I've extended it with a different approach in which you can create a Curio stand-in for the asyncio event loop and submit coroutines to it. Like this::
Under the covers, asyncio is running the event loop in a different thread. The event loop gets shut down automatically when the Curio kernel gets shutdown.
This issue is further discussion about this. What should curio-asyncio bridging look like in a ideal world?
The text was updated successfully, but these errors were encountered: