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

Experiment with uvloop in the Gunicorn worker #6023

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pedro-psb
Copy link
Member

@pedro-psb pedro-psb commented Nov 14, 2024

Just checking if nothing breaks.

#6021


@pedro-psb
Copy link
Member Author

Just a note, maybe we should watch out for this. We've done something about it, but: #5666 (comment)

@pedro-psb pedro-psb force-pushed the experiment-with-uvloop branch from 2b57798 to 720c48e Compare November 14, 2024 15:54
@bmbouter
Copy link
Member

I'm +1 on this!

@pedro-psb pedro-psb marked this pull request as ready for review November 14, 2024 20:43
@pedro-psb pedro-psb force-pushed the experiment-with-uvloop branch from 720c48e to 3aa2307 Compare November 19, 2024 16:00
@github-actions github-actions bot removed the no-issue label Nov 19, 2024
@dralley
Copy link
Contributor

dralley commented Nov 20, 2024

Are we intending to actually merge this now or does it remain just a test? Do we have any idea for example how much of a difference it makes in practice?

@bmbouter
Copy link
Member

I think we should merge it. This only considers the overhead of the loop itself (whereas, in reality the overwhelming majority of the time is in our application code), but if we're comparing asyncio (what we use) versus uvloop, uvloop seems over twice as fast. https://magic.io/blog/uvloop-blazing-fast-python-networking/

@decko
Copy link
Member

decko commented Nov 21, 2024

Do we also need to set the asyncio event loop to use uvloop?
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
https://uvloop.readthedocs.io/user/index.html#using-uvloop

Also, setting this in the entrypoint, is this gonna work to all the application itself?

@@ -66,6 +66,7 @@ dependencies = [
"tablib<3.6.0",
"url-normalize>=1.4.3,<=1.4.3",
"uuid6>=2023.5.2,<=2024.7.10",
"uvloop>=0.21.0,<0.22",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consider adding this as an optional dependency?

Copy link
Member Author

@pedro-psb pedro-psb Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Personally I would prefer to merge this as an optional feature.
Maybe do some discourse post to invite people to give it a try and provide feedback.
And make the default when we are comfortable with that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmbouter Can we start with that? ^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional dependencies seem complicated. To me, the containers we build for the community would still have it installed because I don't think we want to ship options that then require users to rebuild containers. Pulp (imo) should Just Work™

At that point if it's optional in pulpcore, but still in 100% of the officially supported install method we'd do better just to keep it simple.

I'm fine with whatever you all decide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My problem is not having strong evidence. I believe it will be fine (not break things) and improve performance, but I would like a bit more than that before shipping it widely. And also to justify to the build team why we are adding more deps.

I have a proposal which I prefer (over adding as optional and hoping someone will opt-in and provide feedback):

  1. We ship this as a patch on services for a fixed amount of time (1-3 months? on the agenda) with the purpose of gaining more trust (against breaks or regressions).
  2. We conduct some benchmarking (on services or not) and write a report. I would be happy to do/participate on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all of that ^ FWIW.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea because it'll produce some real-world analysis. We can evaluate it first in the staging environment.

To do this we'll need the patch to be applied to this repo. Also have the usage of it enabled/disabled on the presence of an environment variable. If the env var is set use it, if the env var is non-existant don't. That will be the safest because then we can apply the patch and anywhere it goes it'll not break anything.

Then @dkliban or @decko can set the env var in the deployment repo (another repo with other contributors perms that are kind of hard to adjust). Also they can add uvloop to the container build file.

@pedro-psb could you open a patch like that? Feel free to message with us more about it, we'd like to help make it easy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The containers are not the only way we ship pulp. That argument just does not work for me. OTOH more (hard) dependencies increase the possibility for random breakages by dependencies of dependencies interfering with each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can submit the patch.

@pedro-psb
Copy link
Member Author

pedro-psb commented Nov 21, 2024

@decko Do we also need to set the asyncio event loop to use uvloop?

That's literally the only thing that new worker do! 😄
https://github.com/aio-libs/aiohttp/blob/4adb0616a6de8351c45779048610081e000f7c6a/aiohttp/worker.py#L230

Also, setting this in the entrypoint, is this gonna work to all the application itself?

Not sure I understand what you mean. As far as I know, it applies specifically (and only) to new content-app workers.

@dralley
Copy link
Contributor

dralley commented Nov 22, 2024

I think we should merge it. This only considers the overhead of the loop itself (whereas, in reality the overwhelming majority of the time is in our application code), but if we're comparing asyncio (what we use) versus uvloop, uvloop seems over twice as fast. https://magic.io/blog/uvloop-blazing-fast-python-networking/

FWIW, that benchmark is 8 years old. I'm sure it's faster but I wouldn't want to assume it's along the lines of those numbers.

@pedro-psb pedro-psb marked this pull request as draft November 27, 2024 18:35
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.

5 participants