Skip to content

Speed up Celery task publishing with Redis pipelines - #70455

Open
shivaam wants to merge 2 commits into
apache:mainfrom
shivaam:codex/airflow-investigate-issue-8854
Open

Speed up Celery task publishing with Redis pipelines#70455
shivaam wants to merge 2 commits into
apache:mainfrom
shivaam:codex/airflow-investigate-issue-8854

Conversation

@shivaam

@shivaam shivaam commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

CeleryExecutor currently publishes each task to Redis in a separate network
round trip. This makes publication time grow with both the number of scheduled
tasks and broker latency.

This change lets Celery and Kombu prepare each task message normally, then
buffers the final Redis queue writes in a non-transactional pipeline and
flushes them together. Callback workloads and non-Redis brokers keep the
existing publication path.

Redis pipelining is enabled by default and can be disabled with
[celery] redis_pipelined_publish_enabled = False. The implementation mirrors
Kombu's private Redis transport methods, so a focused contract test will fail
if a future Kombu update changes that integration point.

Local validation:

  • Celery executor unit module: 74 passed, 6 skipped.
  • Linux multiprocessing regression: passed 250 repeated dispatch cycles.
  • PostgreSQL/Celery integration suite: 10 passed with real Redis and RabbitMQ
    brokers and Celery workers.
  • Real daemon load: scheduler, API server, DAG processor, triggerer, PostgreSQL,
    Redis, and a four-process Celery worker completed 1,000/1,000 Bash tasks and
    four/four DAG runs successfully. Redis recorded exactly 1,000 queue writes
    and drained to zero.
  • Changed source files pass mypy; regular prek checks pass. The
    provider-wide manual mypy hook was terminated by the local Docker resource
    limit (exit 137/143).

closes: #8854


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines


Drafted-by: Codex (GPT-5) (no human review before posting)

CeleryExecutor pays one Redis network round trip per task today, which makes scheduler publication latency grow with batch size and broker latency. Large scheduler batches can therefore spend much longer sending work than selecting it.

Keep the existing path available because the optimized Redis integration depends on Kombu transport internals and deployments may prefer compatibility over throughput.
@eladkal

eladkal commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Can you clarify if this change is only for Redis or did you mention Redis because this is the broker you used for testing? Would that work with other brokers like SQS or RabbitMQ?

@shivaam

shivaam commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

This optimization is Redis-only because it relies on Redis pipelines. RabbitMQ and SQS continue using the existing publication path, so their behavior remains unchanged.


Drafted-by: Codex (GPT-5); reviewed by @shivaam before posting

@shivaam
shivaam marked this pull request as ready for review August 22, 2026 14:25
@eladkal

eladkal commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

This optimization is Redis-only because it relies on Redis pipelines. RabbitMQ and SQS continue using the existing publication path, so their behavior remains unchanged.

Drafted-by: Codex (GPT-5); reviewed by @shivaam before posting

Lets maybe add a table to the doc that clarifies which broker supports this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send task to queue in bulk - Celery Executor

2 participants