Skip to content

fix(deletes): retire deployments in small batches to stop worker OOMs - #15122

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/deletes-retire-deployments-batch
Oct 30, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/deletes-retire-deployments-batch

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What

Deployment retention now deletes in batches of 50 instead of utopia-php/database's default 1,000. deleteByGroup gains an optional $batchSize (defaults to Database::BATCH_SIZE, so other callers are unchanged).

Why

fra1 worker-deletes (1Gi) has been OOMKilled ~5×/hour for over a day. One project's hourly maintenance job retires a large backlog of site deployments:

Retiring deployments of sites <project> by requested retention
  └─ deleteByGroup('deployments')
       └─ deleteDocuments(batchSize: 1000)  ← fetches 1000 full rows incl. buildLogs
Time (UTC) Event
10:50:14.681 Retiring deployments … by requested retention
10:50:14 → 10:51:04 cgroup memory 241MB → 1GiB, ~16MB/s (0.5s in-pod sampler)
10:51:04 OOMKilled

The worker dies during the first fetch, so nothing is deleted. The queue retries the job 5 times (30s/2m/10m/10m), and the hourly maintenance enqueues it again, so the backlog never drains. Each kill also drops whatever other deletes jobs were in flight on that worker.

50 rows keeps one batch far below the limit. The throughput cost is negligible because every retired deployment already enqueues its own delete job.

Test

No new test. Per AGENTS.md workers are covered by E2E, and batch size is not observable there. The existing deployment-retention E2E covers the retire path.

Related: appwrite-labs/cloud#6673

@luxor-code-review

luxor-code-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR updates the shared-tables deletion path in Deletes.php so large deployment collections are removed in batches via deleteDocuments() instead of one at a time, reducing memory pressure and iteration overhead during project cleanup. The new optional batch-size argument is forwarded to deleteDocuments() while preserving tenant scoping and per-row callbacks, and a unit test in DeletesTest.php locks the batching behavior.

Files Change
src/Appwrite/Platform/Workers/Deletes.php Switches deployment cleanup to batched deleteDocuments() with a batch-size parameter.
tests/unit/Platform/Workers/DeletesTest.php Adds a unit test covering the batched deletion path.

Reviewed commit: db6f251

@ghost

ghost commented Oct 30, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Deployment retention now deletes deployment documents in batches of 50. The grouped-delete helper accepts an optional batch size and continues using the database default for other callers.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
src/Appwrite/Platform/Workers/Deletes.php Sets a smaller batch size for deployment retention and forwards configurable batch sizes through deleteByGroup.

Reviewed a95ad8a · 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

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/deletes-retire-deployments-batch (after).

Metric Before After Change
🚀 Requests/sec 190.99 199.42 ⚪ +4.4%
⏱️ Latency P50 88.83 ms 86.68 ms ⚪ -2.4%
⏱️ Latency P95 213.07 ms 203.91 ms ⚪ -4.3%
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 86.68 203.91 12,540 199.42 -9.16
Account 163.86 309.25 660 11.21 -2.23
TablesDB 84.25 160.81 6,820 110.69 -17.62
Storage 79.54 183.01 3,300 55.53 -9.64
Functions 122.38 235 1,760 30.33 +4.16

Top API waits (after)

API request Max wait (ms)
account.name.update 474.83
functions.create 438.11
account.prefs.update 433.8
tablesdb.rows.create 413.46
functions.variables.update 383.36

@ChiragAgg5k
ChiragAgg5k merged commit 42b5bfe into main Oct 30, 2026
14 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/deletes-retire-deployments-batch branch October 30, 2026 12:55

@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 S · Looks good to merge. Summary

@ChiragAgg5k ChiragAgg5k self-assigned this Nov 2, 2026
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.

1 participant