Skip to content

Build Swoole from appwrite-labs/swoole-rs - #147

Draft
loks0n wants to merge 1 commit into
mainfrom
feat/swoole-rs
Draft

loks0n wants to merge 1 commit into
mainfrom
feat/swoole-rs

Conversation

@loks0n

@loks0n loks0n commented Nov 16, 2026

Copy link
Copy Markdown
Member

Builds the image's swoole.so from appwrite-labs/swoole-rs v0.1.0, Swoole v6.2.5's PHP extension rewritten in Rust, in place of swoole/swoole-src. Replaces appwrite/appwrite#15690, which did this in Appwrite's own Dockerfile.

What changed

  • Swoole stage. It fetches swoole-rs by commit (3451658, tag v0.1.0) and builds it with Cargo through tools/build_ext.py. The switches are the same as before: c-ares, mysqlnd, the curl hook and the coroutine pgsql driver are passed through --configure. Sockets, Brotli, zstd and OpenSSL are always built in. Rust comes from Alpine's rustup, and the toolchain is the one swoole-rs's rust-toolchain.toml pins (1.100.0). It builds from source because the release binaries leave out the curl and pgsql hooks.
  • Updater. The swoole dependency now follows swoole-rs's tags. The v6.2.4 exclusion was a swoole-src release, so it's gone.
  • Tests. StructureTest's Swoole-version test assumed the pin is the version Swoole reports. With swoole-rs the pin is v0.1.0 while the extension reports 6.2.5, so that test is deleted. tests.yaml still asserts swoole version 6.x.y, and tests-swoole.php still guards the Swoole-Upload-File fix (refactor(http): harden multipart parsing and upload lifecycle swoole/swoole-src#6309).
  • Changelog. Adds CHANGES.md 2.4.0.

Risk

swoole-rs is experimental: its README says nothing runs it in production yet, and its nightly AddressSanitizer run failed on three of the five nights to 2026-11-16. It passes upstream's PHPTs wherever upstream does, and its scheduled run of Appwrite's e2e suite matched stock Swoole on 2026-11-11. The Swoole stage now compiles about 209k lines of Rust, so cold builds are slower.

Testing

  • composer test (158 tests), composer lint, composer check
  • Image build on amd64 and arm64 (not built locally: Docker was unavailable)
  • Structure tests, including tests-swoole.php
  • Appwrite e2e on the new base before Appwrite bumps to it

🤖 Generated with Claude Code

Replace the swoole-src stage with a Cargo build of appwrite-labs/swoole-rs
v0.1.0, Swoole v6.2.5's PHP extension rewritten in Rust, with the same
switches. The weekly updater follows swoole-rs's tags, and the v6.2.4
exclusion and the version test that assumed the pin is the reported
Swoole version go with swoole-src.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@loks0n

loks0n commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Built locally on arm64 (OrbStack, --target final) at 8857fe4:

  • The swoole stage builds in 76s: rustup toolchain install picks up 1.100.0 from rust-toolchain.toml, and --php-sockets finds the compile stage's sockets headers.
  • php --ri swoole: Version 6.2.5, swoole-rs => 0.1.0 (345165801636), with curl-native (curl 8.23.0), c-ares 1.34.9, mysqlnd, coroutine_pgsql (libpq 18.7), sockets, OpenSSL 3.5.9, http2, brotli and zstd enabled. SWOOLE_HOOK_ALL includes the pgsql and native curl hooks.
  • tests.yaml structure tests: 17/17 pass.
  • tests-swoole.php: status 200, target kept.

Not run locally: the xdebug target, amd64, and Appwrite e2e on this base.

@loks0n

loks0n commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Appwrite benchmark: stock Swoole vs swoole-rs

Two Appwrite images (development target, appwrite/appwrite cf5848d) built on two bases from docker-base main: one stock and one with this PR. The bases differ only in swoole.so. Five alternating trials each on one Mac (arm64, OrbStack, 10 CPUs), using swoole-rs's own tools/appwrite_bench.py: ApacheBench with keep-alive and concurrency 32, 5000 requests per read and 500 per write, plus 200 realtime subscriptions. CPU is measured exactly from each Appwrite container's cgroup usage_usec. Memory is sampled with docker stats throughout. Medians below; the ranges are min–max.

Writes are clearly slower. All 0 failures and 0 non-2xx.

endpoint stock req/s swoole-rs req/s change p99 ms stock → rs
document-create 162.6 (141–184) 97.8 (88–106) −40%, no overlap 436 → 940
session-create 103.5 (79–111) 70.3 (47–77) −32% 516 → 839
document-list 817 (771–1063) 719 (477–781) −12% 194 → 402
file-upload 847 801 noise 74 → 75
file-download 2315 2008 noise (ranges overlap) 34 → 39
health-version 8485 10096 noise (5.2k–12.1k both) 14 → 13
locale-countries 2338 2573 noise 18 → 20
realtime-subscribe 582 464 noise (303–638 both) 7.7 → 9.2

CPU and memory are the same.

stock swoole-rs change
CPU-seconds for the whole run (all Appwrite containers) 96.3 96.8 +0.5%
Wall time for the same run 24.4 s 29.6 s +21%
Peak memory under load (all) 2384 MiB 2320 MiB −2.7%
Peak memory under load (appwrite HTTP) 1773 MiB 1707 MiB −3.7%
Idle memory (all) 983 MiB 991 MiB +0.8%
Idle CPU (all) 1.8% 1.8% 0

The same work costs the same CPU but takes 21% longer, so swoole-rs spends more time waiting rather than more time computing. The slow endpoints are the ones that write to PostgreSQL (document and session creates, and document-list's p99), so the coroutine pgsql path is the first suspect. My guess is that it blocks a worker or serialises queries where stock Swoole yields. That needs confirming before this ships.

Caveats: this ran on a laptop with other things running, and read throughput swings around 2× between trials for both variants. The write gap holds in every trial. Both images use the development target, as in swoole-rs's appwrite-e2e.yml.

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