Symfony Benchmarks: Symfony Proxy vs. Varnish
By default Symfony (and eZ Platform) use a reverse proxy written in PHP. This is obviously not the most performant solution, but as a feature complete implementation it allows the framework to function in the same way regardless of whether it's ran with or without a separate Reverse Proxy:
Symfony comes with a reverse proxy (also called a gateway cache) written in PHP. Enable it and cacheable responses from your application will start to be cached right away.
Varnish is a popular high performance reverse proxy that is nowadays a common piece in applications built with PHP. Together with Nginx, Varnish is probably the most common Open Source Reverse Proxy in use today. eZ Platform builds upon the FOSHttpCacheBundle that adds commonly needed functionalities such as invalidation, cache tagging and contextual caching.
The Symfony Framework offers a Hierarchical View architecture by default. This means that in your template files you can render other controllers. Together with support for ESI (Edge Side Includes) it opens up alternative caching strategies by allowing caching of independent fragments.
The framework handles all requests and allows them to be merged on server side through ESI or with the BigPipe strategy on the client side using hinclude.js. In our case we are looking at server side performance and will focus on Varnish and ESI, and not skewing results by serving out a skeleton page with placeholders.
Varnish vs. Symfony Proxy Performance
This series is ran with 8 Core and 8 GB RAM against the eZ Platform Demo installation front page and a simple REST API call. Varnish version is 4.0 and it's setup with the standard configuration that ships with eZ Platform: varnish4.vcl
Tests are ran three times at concurrency of 10 and average values are reported.
Rather unsurprisingly Varnish is the more performant option. Varnish outperforms the Symfony Proxy by a factor of 5 to 6 when running on a single CPU. With added CPU resources the PHP inches closer in relative terms, clearly benefitting from the added processing power. Varnish makes little gains in the range from 1 to 4 CPU cores, but takes a leap in the 8 core configuration.
The proxy shipped with the Symfony Framework is no competition for a dedicated Reverse Proxy server such as Varnish. It is fully featured and allows for the upgrade of applications from a simplistic PHP setup to a load balanced reverse proxied environment without application changes.
As a sort of polyfill the Symfony Proxy does it's job adequately, but will likely fall behind even more as complexity grows. The proxy layer in general is increasingly becoming a layer combining fragments to build a complete website - either on the server or on the client side with render_esi.
This allows for more efficient use of processing resources as a number simpler tasks can be ran in parallel and cached separately. There is nothing stopping the use of ESI or the BigPipe strategy can even be used as an integration point for separate applications, together with inter-app comms done in message queues such as ZeroMQ, IronMQ or RabbitMQ.
In the next article we'll take a look at how running Symfony and eZ Platform as a continuous PHP process affects the performance.