Hacker News new | ask | show | jobs
by helldritch 2216 days ago
I agree with everything you've said, with the exception that it doesn't fit our usecase.

We run and maintain several Symfony applications, we're very familiar with frameworks, how they work, their strengths and weaknesses.

This was a carefully considered route:

We wanted to be writing PHP code with high performance and strict response time requirements, as such:

* Symfony was instantly ruled out.

* We knew we would struggle to do this with raw PHP but didn't want to retrain the team to learn a new language (our thinking being we would likely write something inferior and insecure).

* We considered Phalcon and Swoole and ultimately decided on Swoole as we found Phalcon a bit too opinionated. That being said, Swoole's documentation isn't great so we've had to internally document it. (We will probably push a few documentation PRs for swoole-src when we're done).

* We didn't trust a big framework to have zero memory leaks, which is a key issue for long running Swoole processes, since it's not a typical issue for the single-use PHP processes we are used to.

With regards to documentation, it's very well documented (with documentation explaining the reasoning behind each class, usage, pitfalls and how it fits in to the larger application, and documentation for the wider ergonomics of the application, debugging, performance considerations, etc), with a 96% test php-unit coverage for the Framework.

Your concerns are very well received and are concerns we have had from the beginning. Constant vigilance and a deep respect for my co-workers is what keeps this little project on the straight and narrow.

1 comments

What were your constraints in performance? I'm surprised Laravel is considered slow.

Have you considered sticking to it and applying some caching layer on top of it?

It's part of a live video platform for a gaming company which needs extra information to be overlaid on top of their live stream (for the customer in-video frame performance is incredibly important: the stream run at 30fps (so a maximum of 33ms per frame) and the overlay information has to be generated in 11ms or less)

We did originally consider writing it in Rust (it would have been my personal preference) but the consensus was that since the rest of the tooling for this customer is in PHP we didn't want to add a skillset they didn't have internally if they were to move away from us in the future (we aren't big on needless vendor lock-in and prefer to compete on quality and service).

We experimented with PHP7.4 and Symfony / Laravel and found that we didn't have the performance leeway we needed, even with preloading / opcache.

We opted for Either Swoole or Phalcon, tried them both and found that Swoole was more to our liking and was somewhat more performant than Phalcon in our real-world testing.

We are exposing Swoole directly to them within their VPC, so we were able to do away with NGINX as a reverse proxy as well and have Swoole handle the HTTP request phase and HTTPS. We were able to make heavy use of Swoole\Table to save superfluous trips to Redis and run a Redis synchronisation process in a coroutine thread when the concurrent number of network tasks drops below 16.

Our end service response times (including network overhead) are around here:

- Mean response time: 4ms

- Fastest: 2ms

- 99th percentile: 9ms

- 999th permille: 10ms

One unforeseen side effect is that it has a crazy amount of scalability built in by default, the 8core machine the process runs on can easily scale up to 15,000 concurrent requests (as in 15,000 requests per second) without going over 15ms for response times, and can scale up to 45,000 concurrent requests before things start to "break".

Also: Our issues with Laravel / Symfony weren't just performance, but also statefulness and memory leaks. Circular references, etc, which persist throughout multiple network requests. In a normal PHP flow using php-fpm or apache-php-cgi this isn't an issue: The PHP process is created, used and thrown away. For a Swoole setup, these memory leaks quickly get out of control and cause performance issues, instability and very occasionally superfluous garbage collection runs.