My goal with this demo was to build a real-time, multiplayer app that can scale to thousands of concurrent, long-lived connections. Using PHP.
Laravel Octane keeps the bootstrapped app loaded in memory, which can scale to thousands of requests per second for the toggling of cells. A separate script starts a Swoole HTTP server to make async I/O work in PHP for serving long-lived SSE connections. The event stream is compressed using gzip by the web server (standard Nginx). The app uses Redis pub/sub for real-time messaging, and a Redis key-value store for state persistence. Rate limiting on the server helps prevent automated bots causing too much havoc.
Finally, reactivity is powered by Datastar with one event listener and one long-lived SSE connection to the backend.
Would be cool to see some logs on server load, it's one thing to claim "scale to thousands of requests per second" it's another to show the logs of a €4 VPS doing it. I don't doubt it, when I did a similar experiment with golang I never noticed any real issues (aside from a misconfiguration at the proxy requiring a min size on the SSE response) but it would still be neat to see the logs/active users.
Agreed! I have a WIP article in which I describe in the setup in more detail. I’ll also include load testing benchmarks as part of it. The key to reaching high scale is keeping things simple, and there’s really very little that the app is doing. Swoole and Redis are doing the heavy lifting, and they’re both heavily optimised for scale out-of-the-box.
My goal with this demo was to build a real-time, multiplayer app that can scale to thousands of concurrent, long-lived connections. Using PHP.
Laravel Octane keeps the bootstrapped app loaded in memory, which can scale to thousands of requests per second for the toggling of cells. A separate script starts a Swoole HTTP server to make async I/O work in PHP for serving long-lived SSE connections. The event stream is compressed using gzip by the web server (standard Nginx). The app uses Redis pub/sub for real-time messaging, and a Redis key-value store for state persistence. Rate limiting on the server helps prevent automated bots causing too much havoc.
Finally, reactivity is powered by Datastar with one event listener and one long-lived SSE connection to the backend.
It all runs on a €4 Hetzner VPS.
Would be cool to see some logs on server load, it's one thing to claim "scale to thousands of requests per second" it's another to show the logs of a €4 VPS doing it. I don't doubt it, when I did a similar experiment with golang I never noticed any real issues (aside from a misconfiguration at the proxy requiring a min size on the SSE response) but it would still be neat to see the logs/active users.
Agreed! I have a WIP article in which I describe in the setup in more detail. I’ll also include load testing benchmarks as part of it. The key to reaching high scale is keeping things simple, and there’s really very little that the app is doing. Swoole and Redis are doing the heavy lifting, and they’re both heavily optimised for scale out-of-the-box.
Just wait til he embraces Go and uses Frankenphp + Mercure or NATS - a single binary that'll run on a raspberry pi!
Is this ANOTHER datastar mention at the top of hacker news? Who the fuck are these people? Seems like a cult
astroturf campaign?
ngmi