Symfony Benchmarks: Symfony Microkernel, Lumen, Silex, Slim...
There are a number of PHP microframeworks such as Silex and Slim in use today. The recently introduced Symfony Microkernel has a few advantages over stand alone microframeworks, notably being able to reuse existing Bundles.
Have a Lumen project you want to upgrade to the full Laravel framework? It couldn't be easier. Since Lumen is powered by Laravel's components, just drop your code into a Laravel installation. You won't have to change a thing.
In a series of benchmarks we've taken a look at some ways Symfony performance is affected by runtimes, resources and more. To end the series we'll take a look at how different implementations handle a similar task.
Comparing Symfony Microkernel, Silex, Slim and more...
In this case we'll take the same server setup as before; Configured with 1 CPU, 4 GB and PHP 7. We'll perform a rather simple task of serializing a small object to JSON and spitting it out with the correct headers. Serialized result contains a timestamp that is dynamic for each request.
The options undergoing tests are:
- Symfony 3.0.1 SE (AppKernel)
- Symfony 3.0.1 SE (Micro Kernel)
- Symfony 2.8.1 SE (AppKernel with PHP-PM)
- Lumen 5.1.4
- Silex 1.3.5
- Slim PHP 3.0.0
- Raw HTTPKernel implementation
- Raw PHP implementation
All of the runs are repeated three times with a concurrency of 50 and averages are reported.
Results vary greatly from around 500 req/s to over 10000 req/s. Obviously the Raw PHP and HTTPKernel options only setting the baseline maximum performance expectations as very functionally limited implementations.
The raw PHP implementation only does the JSON serialisation, setting headers and sending output. It's easily the fastest option. The Symfony HTTPKernel option has some rudimentary routing, but has very little application logic in addition to that.
With Silex being neck-to-neck with the main Symfony Framework, I view that the overhead (both complexity and performance wise) are now neglible. Especially considering that nothing is stopping me from branching the lightweight app to a separate app directory.
Lumen and the Symfony Microkernel are both excellent options for offering a simplistic backend for existing Laravel or Symfony Framework projects starting from today.
The PHP-PM driven Symfony2 framework performs well, offers a full featureset but might be a bit too experimental for some. This is obviously a continuously evolving playing field that everyone, including Symfony and PHP need to keep up with the times:
- Add support for Websockets and real-time applications [to Symfony]
- Asynchronous PHP - Christopher Pitt
- Async PHP with React
- Anthony Ferrara - High Performance PHP
Each of the benchmarked options will start immediately degrading in performance when you start solving real problems and introducing mistakes in your logic.
After all, it's good to remember that regardless of the cool factor of your tech stack and high numbers in benchmarks.... It's likely that:
You don't have scalability problems
Your code just sucks