Skip to content

fix(usage): use queued project context in stats-usage worker - #14106

Merged
HarshMN2345 merged 1 commit into
mainfrom
fix/stats-usage-project-context
Oct 5, 2026
Merged

HarshMN2345 merged 1 commit into
mainfrom
fix/stats-usage-project-context

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

The stats-usage worker injected `project`, which runs `getDocument('projects', ...)` on the platform database for every usage job. The worker only needs the project's `$id` and `$sequence`, and both are already in the queued payload. It now injects `projectContext` instead. I removed the payload-vs-resolved project ID check because it would only compare the payload with itself.

#13480 made the same change and was closed as CE-only. Since then, #13764 makes cloud extend this worker rather than keep its own copy, so the lookup would apply there too. #14086 also measured about 25 points less worker CPU from this change alone. The change doesn't overlap #13764 and merges cleanly with it.

Verification: a harness resolved the worker's injections through `app/init/worker/message.php` for 1000 jobs and counted project lookups. It saw 1000 `getDocument('projects')` calls before the change and 0 after. Pint and PHPStan pass on the changed file.

Part of #14086

@ghost

ghost commented Oct 5, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The queued usage payload includes the required sequence, and the existing per-message ProjectContext resource preserves the worker's tenant contract.

The stats-usage worker now uses the queued ProjectContext instead of resolving a project document from the platform database. It takes the tenant sequence from that context and removes the now-redundant payload-versus-resolved project ID check.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
src/Appwrite/Platform/Workers/StatsUsage.php Switches injection and action parameter to ProjectContext and uses its sequence for usage writes.

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

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/stats-usage-project-context (after).

Metric Before After Change
🚀 Requests/sec 191.16 166.7 🔴 -12.8%
⏱️ Latency P50 88.93 ms 104.67 ms 🔴 +17.7%
⏱️ Latency P95 214.38 ms 242.25 ms 🔴 +13%
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 104.67 242.25 10,374 166.7 +27.87
Account 195.29 382.37 546 9.14 +66.33
TablesDB 101.28 195.04 5,642 92.33 +26.82
Storage 95.04 206.82 2,730 46.56 +15.16
Functions 144.13 282.68 1,456 25.56 +30.49

Top API waits (after)

API request Max wait (ms)
functions.create 604.58
account.name.update 603.3
storage.files.create 470.01
storage.buckets.create 463.62
account.prefs.update 456.79

@HarshMN2345
HarshMN2345 merged commit f4bad37 into main Oct 5, 2026
50 checks passed
abnegate added a commit that referenced this pull request Oct 5, 2026
Merges main a2cca78 (#14009, #14106, #14117, #14115, #14119, #14114,
#14101, #14125, #14129, #14127) so cloud#5410 can require a train head
that contains main at or after 0ed7232.

Conflicts: none.

Database 8.0 port: none needed. Main's new code only uses Document
getAttribute/setAttribute and Query::equal/lessThan/orderAsc/limit
(Tasks/Interval.php), all unchanged in database 8.0; no removed
Database::* constants, config collections, or model magic reads.
composer.json and composer.lock are untouched by main, so the train's
database and migration pins stay as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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