Symfony Benchmarks: Symfony Proxy vs. Varnish

In the previous articles we have evaluated PHP performance on different runtimes (PHP 5.6, HHVM, PHP 7) as well as how it behaves when adding server resources (CPU & RAM) using eZ Platform - a CMS built on the Symfony Framework.

In production environments Symfony and eZ Platform are likely ran behind the Varnish Reverse Proxy, which we'll evaluate next by comparing it to the built in Symfony Proxy.

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.
-- Symfony.com

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.

Tests are ran three times at concurrency of 10 and average values are reported.

Front Page with Symfony Proxy and VarnishAPI with Symfony Proxy and Varnish

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.

Conclusion

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.