Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

Symfony Benchmarks: Symfony Microkernel, Lumen, Silex, Slim...

Microservice architectures remain popular and microframeworks of all sorts are an essential part of the scene. At the end of November with the release of Symfony 3.0 (and 2.8) the Symfony Full Stack Framework received an option to use a lighter bootstrap, a Microkernel in Symfony terms.

JavaScript together with Node.js is the current top-of-mind for creating microservices backends and data integrations. As boring as it may be for some, PHP remains as a viable option for companies and individuals with PHP skills and an existing code base.

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.

In additition to the Symfony Microkernel, there is another similar effort. Laravel has had a little brother called Lumen with a practical promise of reuse of existing Laravel code for Microservices:

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.

PHP Microframework and kernel benchmarks

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.

Conclusions

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:

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

https://www.youtube.com/watch?v=qjYyC47rdVs&t=40s

Written by Jani Tarvainen on Wednesday January 6, 2016
Permalink - Tags: symfony, php, lumen, silex, benchmark, laravel

« Symfony Benchmarks: Symfony Proxy vs. Varnish - Boring is the new Awesome »