Skip to content

fix(queue): allow queues on a separate Redis via _APP_REDIS_QUEUE_* - #14112

Draft
HarshMN2345 wants to merge 4 commits into
mainfrom
fix/separate-queue-redis
Draft

HarshMN2345 wants to merge 4 commits into
mainfrom
fix/separate-queue-redis

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Cache, pub/sub, locks, abuse and every queue share one Redis, and the default compose runs it with allkeys-lru. A backlog in v1-stats-usage pushes the cache out, and it can also evict queue lists, which loses every job in them.

This adds optional _APP_REDIS_QUEUE_HOST/PORT/USER/PASS. When _APP_REDIS_QUEUE_HOST is set, the publisher pool (API, realtime, scheduler, health) and the worker consumer in app/worker.php connect to that instance. Cache, pub/sub, lock and abuse stay on _APP_REDIS_*. When it is unset, nothing changes. The variables are documented in app/config/variables.php and passed through in docker-compose.yml. The default topology stays the same.

The queue instance should run with maxmemory-policy noeviction. Then a full queue Redis rejects new jobs instead of silently dropping old ones. Don't use noeviction on the shared instance, because cache writes would start failing.

Fixes #14084

Verification

  • Before: in a 20 MB allkeys-lru Redis, pushing 12,000 jobs of 2.1 KB evicted 4,983 keys. Only 19 of 5,000 cache keys survived. The idle v1-mails list was evicted, and only 3,000 of the 12,000 v1-stats-usage jobs remained. With noeviction, nothing was evicted and the push failed with OOM.
  • Wiring: a script that publishes through $pools->get('publisher') and builds the consumer from app/worker.php. On main, setting _APP_REDIS_QUEUE_HOST had no effect. With this change, the job and the consumer go to the queue instance, and the lock pool stays on the main one. Password auth was also checked. With the variable unset, behaviour is the same as before.
  • pint and phpstan pass on the touched files. tests/unit/Docker passes.

@ghost

ghost commented Oct 5, 2026

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The new queue-routing behavior needs automated regression coverage before merging.

Adds optional Redis connection settings for a dedicated queue instance, routing both publishers and worker consumers to it when configured. Documents the settings and the recommended noeviction policy, and forwards them through the Compose services while retaining the shared-Redis fallback.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Add regression coverage for dedicated queue Redis routing app/init/registers.php:61
Fix with agent prompt
### Issue 1
app/init/registers.php:61-67
**Add regression coverage for dedicated queue Redis routing**

The new publisher/consumer routing has no automated coverage, despite existing queue integration tests in `tests/e2e/General/WorkerConcurrencyTest.php`. Please add an integration case proving a published job is consumed on the dedicated instance while cache/lock traffic stays on the main instance, plus the unset-host fallback; the reported manual script and Docker unit tests won't catch a future wiring regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 4
File Change
app/config/variables.php Documents four optional queue Redis settings and the dedicated-instance eviction policy.
app/init/registers.php Routes the publisher pool to the dedicated queue Redis when a queue host is configured.
app/worker.php Uses the queue Redis settings for both consumer connections, with the existing fallback.
docker-compose.yml Passes queue Redis environment variables through to application services.

Reviewed 1fe223b · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Comment thread app/init/registers.php
Comment on lines +61 to +67
$fallbackForQueue = empty(System::getEnv('_APP_REDIS_QUEUE_HOST', '')) ? $fallbackForRedis : 'redis_main=' . AppwriteURL::unparse([
'scheme' => 'redis',
'host' => System::getEnv('_APP_REDIS_QUEUE_HOST', ''),
'port' => System::getEnv('_APP_REDIS_QUEUE_PORT', '6379'),
'user' => \rawurlencode(System::getEnv('_APP_REDIS_QUEUE_USER', '')),
'pass' => \rawurlencode(System::getEnv('_APP_REDIS_QUEUE_PASS', '')),
]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add regression coverage for dedicated queue Redis routing

The new publisher/consumer routing has no automated coverage, despite existing queue integration tests in tests/e2e/General/WorkerConcurrencyTest.php. Please add an integration case proving a published job is consumed on the dedicated instance while cache/lock traffic stays on the main instance, plus the unset-host fallback; the reported manual script and Docker unit tests won't catch a future wiring regression.

Prompt To Fix With AI
This is a comment left during a code review.
Path: app/init/registers.php
Line: 61-67

Comment:
**Add regression coverage for dedicated queue Redis routing**

The new publisher/consumer routing has no automated coverage, despite existing queue integration tests in `tests/e2e/General/WorkerConcurrencyTest.php`. Please add an integration case proving a published job is consumed on the dedicated instance while cache/lock traffic stays on the main instance, plus the unset-host fallback; the reported manual script and Docker unit tests won't catch a future wiring regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@HarshMN2345
HarshMN2345 marked this pull request as draft October 5, 2026 06:41
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/separate-queue-redis (after).

Metric Before After Change
🚀 Requests/sec 201.69 216.93 🟢 +7.6%
⏱️ Latency P50 84.9 ms 79.26 ms 🟢 -6.6%
⏱️ Latency P95 201.32 ms 188.85 ms 🟢 -6.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 79.26 188.85 13,680 216.93 -12.48
Account 149.8 290.19 720 12.2 -13.78
TablesDB 76.24 143.77 7,440 121.38 -27.26
Storage 73.01 170.53 3,600 59.87 -4.07
Functions 115.41 223.42 1,920 32.67 +2.99

Top API waits (after)

API request Max wait (ms)
functions.create 678.24
account.name.update 451.65
functions.variables.update 376.37
functions.delete 362.48
functions.variables.create 341.34

2.4.0 was released without these variables, so they cannot have been
introduced in 2.3.1.
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@14112

commit: d85fd26

This branch has not been deployed

No deployments
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.

🐛 Bug Report: Usage queue backlog evicts the cache from Redis

1 participant