swoole / docker-swoole

🏄 Official Docker Image of Swoole
https://hub.docker.com/r/phpswoole/swoole
Apache License 2.0
534 stars 113 forks source link

Investigate Performance Disparity: Benchmarks of Swoole PHP in Alpine vs. Ubuntu Images #44

Closed daalvand closed 1 year ago

daalvand commented 1 year ago

I conducted performance benchmarks on a simple Swoole PHP "hello world" application, comparing its requests per second (RPS) on both an Ubuntu image and an Alpine image.

Surprisingly, the Ubuntu image yielded 35,000 RPS, while the Alpine image only achieved 15,000 RPS.

I'm seeking an explanation for this significant performance difference. Metrics suggest that Alpine may be negatively impacting performance.

Any insights or explanations would be greatly appreciated!

deminy commented 1 year ago

I'm sorry to say I can't provide an exact reason for your observation.

While the "Hello World!" test can provide a simple performance measure, it's not a comprehensive benchmark for Swoole applications. To illustrate, if we were to print "Hello World!" 1,000,000,000 times, the time and memory consumed would likely be similar whether you use Swoole or not.

The main strength of Swoole, particularly when compared to PHP-FPM, lies in its concurrent IO processing. This is particularly beneficial for operations such as database queries, API calls, and file manipulations. In most PHP applications, server time is predominantly consumed by IO operations, often forming the bottleneck. Hence, a more representative benchmark for Swoole would include some IO operations. This kind of benchmarking scenario is more reflective of real-world use cases for web applications.

I have previously performed a different benchmark using Swoole, where I invoked numerous sleep() functions (where each sleep() function call can be considered as a tiny concurrent job/request). While not directly comparable, I hope it provides some insight into the performance characteristics of Swoole.

Thanks