Created
March 26, 2023 16:10
-
-
Save ankurdhuriya/871a7a3d7292727189f8090a8027e4fc to your computer and use it in GitHub Desktop.
Celery Prefetching Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In this example, we're configuring Celery to prefetch 10 tasks at a time. | |
This means that each worker will load up to 10 tasks into its memory before | |
they are executed. This can help to reduce the time it takes to fetch new | |
tasks from the broker, and can improve overall performance. | |
""" | |
from celery import Celery | |
app = Celery('tasks', broker='pyamqp://guest@localhost//') | |
# Configure Celery to prefetch 10 tasks at a time | |
app.conf.update( | |
worker_prefetch_multiplier=10 | |
) | |
@app.task | |
def add(x, y): | |
return x + y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment