Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
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

Use uvloop for async event loop #1842

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Use uvloop for async event loop #1842

wants to merge 2 commits into from

Conversation

mattt
Copy link
Member

@mattt mattt commented Jul 31, 2024

From https://github.com/MagicStack/uvloop:

uvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses libuv under the hood.

Hard to argue with 2x speedup for a drop-in replacement. Curious to see whether that holds up.

@mattt mattt requested a review from a team July 31, 2024 20:49
@mattt
Copy link
Member Author

mattt commented Jul 31, 2024

There's a good chance we're already using it implicitly. I just wanted to test this by making it explicit.

@yorickvP
Copy link
Contributor

yorickvP commented Aug 1, 2024

How well does this combine with customers of our library who use asyncio? Should there maybe be an escape hatch?

@mattt
Copy link
Member Author

mattt commented Aug 1, 2024

@technillogue pointed out that uvloop was already added to the async branch via httpx. Uvicorn advertises that the default "auto" loop setting selects uvloop when available, and I don't see any evidence to the contrary.

@yorickvP That's a good callout, but I don't anticipate a problem. The vast majority of consumers will run cog.http as a self-contained program, and anyone consuming as a library could pretty easily swap out their preferred event loop as desired.

@mattt mattt closed this Aug 1, 2024
@mattt mattt deleted the mattt/uvloop branch August 1, 2024 11:32
@yorickvP
Copy link
Contributor

yorickvP commented Aug 2, 2024

The reason I ask is that, with async cog, we saw people trying to combine it with their own event loops in their own threads, and it took a bit of hacking to make that work.

@mattt mattt restored the mattt/uvloop branch August 12, 2024 11:15
@mattt mattt reopened this Aug 12, 2024
@mattt mattt changed the base branch from async to main August 12, 2024 11:15
@mattt
Copy link
Member Author

mattt commented Aug 12, 2024

Reopening to apply changes to main, which doesn't (yet) have httpx dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants