Skip to content

Instantly share code, notes, and snippets.

@ankurdhuriya
Created March 26, 2023 16:10
Show Gist options
  • Save ankurdhuriya/871a7a3d7292727189f8090a8027e4fc to your computer and use it in GitHub Desktop.
Save ankurdhuriya/871a7a3d7292727189f8090a8027e4fc to your computer and use it in GitHub Desktop.
Celery Prefetching Example
"""
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