Skip to content

perf: enable OPcache and Hyperloop B - #13487

Merged
loks0n merged 7 commits into
mainfrom
codex/enable-opcache-hyperloop-b
Sep 4, 2026
Merged

loks0n merged 7 commits into
mainfrom
codex/enable-opcache-hyperloop-b

Conversation

@loks0n

@loks0n loks0n commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Enable Cloud's PHP OPcache configuration in the Appwrite image, including CLI caching, a 384 MiB cache and tracing JIT with a 128 MiB buffer. Production images disable timestamp validation. Development images enable timestamp validation with no revalidation delay so worker reloads pick up bind-mounted source changes.

Apply the HTTP adapter's Hyperloop B preset for coroutine hooks, FD-bound dispatch, send yielding and runtime tuning. Preserve Appwrite's configured worker count and 12 MiB payload/output limits. Select coroutine-aware Swoole connection pools in the HTTP entrypoint, through a fresh registry adapter per pool, including installations that still configure the legacy stack adapter; the stack adapter cannot wait when concurrent requests exhaust a pool.

Parallel chunk uploads finalize only after the merged metadata records every completed chunk write; files still being written must not count toward completion. They also check the completed file document under the existing lock before rejecting an empty chunk count. A concurrent finalizer can remove chunk files before another request counts them, which otherwise returns a spurious 500.

Test Plan

  • All 42 CI jobs passed on 48ecaccecd533424f194dc925df0e32a1388f530: image build, static checks, security scanning, unit tests, E2E suites and benchmark.
  • The existing parallel large-file upload E2E test was observed failing before the corrections (first a spurious 500, then a truncated download); it now passes its response, downloaded size and SHA-256 checks.
  • E2E suites pass with Swoole pools across HTTP, Realtime, workers and CLI tasks, including migrations and scheduled functions.
  • Runtime container checks confirmed CLI OPcache and tracing JIT are active, production timestamp validation is disabled, and development enables immediate timestamp revalidation.
  • Latest CI benchmark versus main: 235.45 requests/sec (+0.4%) and 166.09 ms P95 latency (-0.6%).
  • Greptile reviewed this commit with confidence 5/5 and no actionable findings.

Related PRs and Issues

Matches the configuration in Appwrite Cloud.

Checklist

  • Read the contributing guidelines.
  • No API metadata or SDK specification changes.

@greptile-apps

greptile-apps Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR enables and tunes PHP OPcache, applies the Hyperloop B HTTP runtime preset, standardizes shared connection pools on the coroutine-aware Swoole adapter, and corrects concurrent chunk-upload completion handling.

  • Adds production OPcache and tracing JIT configuration, with immediate timestamp revalidation in development images.
  • Applies Hyperloop B while preserving Appwrite’s worker and payload limits.
  • Removes the legacy pool-adapter switch and consistently creates Swoole pools.
  • Uses merged, completed upload-part metadata when deciding whether to finalize a chunked file.
  • The previous stale-development-code finding is fully addressed by the development-specific timestamp-validation override.

Confidence Score: 5/5

The PR appears safe to merge, with the previous development OPcache issue fixed and no actionable new defect established.

The development image now overrides production timestamp behavior with opcache.validate_timestamps=1 and opcache.revalidate_freq=0, fully addressing the previous finding. The latest chunk-upload adjustment checks completed documents under the lock, merges persisted and current part metadata, and preserves the upload result when part metadata is unavailable; no blocking failure remains.

Important Files Changed

Filename Overview
Dockerfile Installs the shared OPcache configuration and adds a development override that revalidates bind-mounted PHP source immediately.
docker/opcache.ini Enables CLI OPcache, a 384 MiB cache, and tracing JIT while disabling production timestamp validation.
app/http.php Applies Hyperloop B settings and then overrides worker count and request/output size limits with Appwrite-specific values.
app/init/registers.php Replaces configurable stack pools with fresh coroutine-aware Swoole pool adapters.
docker-compose.yml Removes the obsolete pool-adapter environment setting from all services.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Create.php Bases finalization on merged completed-part metadata to avoid counting chunk files that are visible before their writes finish.

Reviews (5): Last reviewed commit: "fix(storage): finalize only after all ch..." | Re-trigger Greptile

Comment thread docker/opcache.ini
opcache.memory_consumption=384
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=65536
opcache.validate_timestamps=0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Development Serves Stale Code

This configuration is inherited by the development image, where app/ and src/ are bind-mounted into a persistent PHP process. With CLI OPcache enabled and timestamp validation disabled, edits to cached PHP files are ignored until the process restarts, breaking the live-edit development workflow. Apply this setting only to immutable production images or override it for development.

Knowledge Base Used: Application bootstrap and runtime lifecycle

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker/opcache.ini
Line: 6

Comment:
**Development Serves Stale Code**

This configuration is inherited by the development image, where `app/` and `src/` are bind-mounted into a persistent PHP process. With CLI OPcache enabled and timestamp validation disabled, edits to cached PHP files are ignored until the process restarts, breaking the live-edit development workflow. Apply this setting only to immutable production images or override it for development.

**Knowledge Base Used:** [Application bootstrap and runtime lifecycle](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/application-bootstrap.md)

---

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

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/enable-opcache-hyperloop-b (after).

Metric Before After Change
🚀 Requests/sec 234.62 235.45 ⚪ +0.4%
⏱️ Latency P50 76.18 ms 76.48 ms ⚪ +0.4%
⏱️ Latency P95 167.02 ms 166.09 ms ⚪ -0.6%
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 76.48 166.09 14,763 235.45 -0.94
Account 138.19 248.39 777 13.15 -27.63
TablesDB 77.32 139 8,029 131.12 -1.18
Storage 63.7 144.39 3,885 65.17 +4.97
Functions 101.17 189.84 2,072 35.35 -13.62

Top API waits (after)

API request Max wait (ms)
storage.files.create 395.1
account.prefs.update 382.11
functions.variables.create 331.13
account.name.update 329.98
functions.create 309.17

@loks0n
loks0n merged commit 4ed3076 into main Sep 4, 2026
45 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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