SlideShare a Scribd company logo
Handling 10k Requests/second
With Symfony and Varnish
Alexander Lisachenko
About me:
lisachenko
lisachenko
‣ Head of Software Architecture
at Alpari (RU) Forex Broker
About me:
lisachenko
lisachenko
‣ Head of Software Architecture
at Alpari (RU) Forex Broker
‣ Have worked with computers
since 7 years old
About me:
lisachenko
lisachenko
‣ Head of Software Architecture
at Alpari (RU) Forex Broker
‣ Have worked with computers
since 7 years old
‣ Clean code advocate, guru in
enterprise architecture
About me:
lisachenko
lisachenko
Author of the Go! AOP
Framework
‣ http://go.aopphp.com
Agenda
Agenda
‣ We review briefly the process of typical
Symfony site growing
Agenda
‣ We review briefly the process of typical
Symfony site growing
‣ What is Varnish and why it’s so popular
Agenda
‣ We review briefly the process of typical
Symfony site growing
‣ What is Varnish and why it’s so popular
‣ How to prepare your Symfony site for
Varnish?
Agenda
‣ We review briefly the process of typical
Symfony site growing
‣ What is Varnish and why it’s so popular
‣ How to prepare your Symfony site for
Varnish?
‣ VCL tricks to easily handle 10K
requests/second with Symfony
Site Growing
First deploy to the production
First deploy to the production
First deploy to the production
1-30 RPS
First marketing campaign
First marketing campaign
First marketing campaign
First marketing campaign
30-50 RPS
Configuring cacheing layer
Configuring cacheing layer
OpCache
Configuring cacheing layer
OpCache MemCache
60-250 RPS
Preparing several backends
OpCache MemCache
Preparing several backends
OpCache MemCache
250-1k RPS
Preparing several backends
OpCache MemCache
250-1k RPS
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016
Reverse proxy caching
OpCache MemCache
Reverse proxy caching
OpCache MemCache
Varnish
1k-20k RPS
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016
Varnish is an HTTP accelerator designed
for content-heavy dynamic web sites as
well as heavily consumed APIs.
Websites using Varnish
Source: https://trends.builtwith.com
Websites using Varnish
Source: https://trends.builtwith.com
Simple workflow:
Simple workflow:
GET /some-web-page
Simple workflow:
GET /some-web-page
X-Cache: MISS
Simple workflow:
GET /some-web-page
X-Cache: MISS
GET /some-web-page
Simple workflow:
GET /some-web-page
X-Cache: MISS
GET /some-web-page
Simple workflow:
GET /some-web-page
X-Cache: MISS
GET /some-web-page
Simple workflow:
GET /some-web-page
X-Cache: MISS
GET /some-web-page
First request to the page - Time To Load 200ms
Simple workflow:
Simple workflow:
GET /some-web-page
Simple workflow:
GET /some-web-page
X-Cache: HIT
Simple workflow:
GET /some-web-page
X-Cache: HIT
Simple workflow:
GET /some-web-page
X-Cache: HIT
Simple workflow:
GET /some-web-page
X-Cache: HIT
Subsequent request to the page - Time To Load 10ms
Idea: do not ask your backend
as much as possible.
How to speed up your site
with Varnish?
How to speed up your site
with Varnish?
Read the RFC 7232-7234
Your friends:
https://tools.ietf.org/html/rfc7234 - Caching
https://tools.ietf.org/html/rfc7232 - Conditional requests
Read the RFC 7232-7234
‣ Cache-Control
Your friends:
https://tools.ietf.org/html/rfc7234 - Caching
https://tools.ietf.org/html/rfc7232 - Conditional requests
Read the RFC 7232-7234
‣ Cache-Control
‣ Expires
Your friends:
https://tools.ietf.org/html/rfc7234 - Caching
https://tools.ietf.org/html/rfc7232 - Conditional requests
Read the RFC 7232-7234
‣ Cache-Control
‣ Expires
‣ ETag
Your friends:
https://tools.ietf.org/html/rfc7234 - Caching
https://tools.ietf.org/html/rfc7232 - Conditional requests
Read the RFC 7232-7234
‣ Cache-Control
‣ Expires
‣ ETag
‣ Last-Modified
Your friends:
https://tools.ietf.org/html/rfc7234 - Caching
https://tools.ietf.org/html/rfc7232 - Conditional requests
Install Varnish
https://www.varnish-cache.org/releases/index.html - Releases and installation guides
For Debian
For FreeBSD
Also available for Amazon Web Services
Configure the backend
Configure the backend
Time for experiments!
Test page with 3 widgets, emulating slow query
Test page with 3 widgets, emulating slow query
…our simple slow action implementation
…our simple slow action implementation
+0.2s +0.5s
+1s
Sequential page loads: ~1 second!
+0.2s +0.5s
+1s
Slow PHP? Slow Symfony?
Slow backend?
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016
Make your responses HTTP
Cacheable with Varnish
Make your responses HTTP
Cacheable with Varnish
Make your responses HTTP
Cacheable with Varnish
Looks good…
Looks good…
Looks good…
…until the cache expires
…until the cache expires
…until the cache expires
Pros and cons of simple
cacheing
+ Page can be cached by Varnish, allowing for
faster responses.
+ Very simple to configure and use.
- Delays in the response time after cache expiration.
- We can not update information in the blocks
without a full page refresh.
- We need to render all 3 blocks at once.
How can we avoid delays on cache
expiration?
Make your backend
requests asynchronous!
Make your backend
requests asynchronous!
Make your backend
requests asynchronous!
Make your backend
requests asynchronous!
Serving stale content while invalidating
Serving stale content while invalidating
Serving stale content while invalidating
Serving stale content while invalidating
Serving stale content while invalidating
Pros and cons of async
cacheing
+ Page can be cached by Varnish, allowing for
faster responses.
+ Very simple to configure and use.
+ No delays after cache expiration.
- We can not update information in the blocks
without full page refresh.
- We need to render all 3 blocks at once.
How can we update each widget
separately on the page?
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Enable Edge-Side Includes
(ESI)
Common mistake - missed cache header
for an ESI block!
Common mistake - missed cache header
for a ESI block!
Common mistake - missed cache header
for a ESI block!
Page with ESI-blocks
Page with ESI-blocks
Pros and cons of async ESI
cacheing
+ Page can be cached by Varnish, allowing for faster
responses.
+ No delays after cache expiration.
+ We can update information in the blocks without
full page refresh.
+ We render and cache each block separately. This
will result in less memory usage and better hit rate.
- Can be dangerous if used without control.
VCL tricks for better performance
Those cookies…
Those cookies…
Tips:
Tips:
‣ Always cache top-level GET-responses;
remove any cookies for them.
Tips:
‣ Always cache top-level GET-responses;
remove any cookies for them.
‣ Only ESI blocks can receive the session
cookie.
Tips:
‣ Always cache top-level GET-responses;
remove any cookies for them.
‣ Only ESI blocks can receive the session
cookie.
‣ Stateless ESI-blocks will not receive any
cookies at all.
Remove all cookies except
session one
Remove all cookies except
session one
Remove all cookies except
session one
Restore cookie for ESI
requests
Restore cookie for ESI
requests
Preparing cookies
Preparing cookies
Preparing cookies
Cacheing with cookies
Cacheing with cookies
Cacheing with cookies
What you will receive?
Some live results
Some live results
There are only two hard things in
Computer Science:
cache invalidation and naming
things.
-- Phil Karlton
Defining the ACL for Varnish
Defining the ACL for Varnish
Defining the ACL for Varnish
Preparing friendly headers
Performing PURGE requests
Performing PURGE requests
Performing PURGE requests
Single page refresh
Single page refresh
Use FOSHttpCache
http://foshttpcache.readthedocs.io/en/stable/index.html - FOSHttpCache Documentation
https://github.com/FriendsOfSymfony/FOSHttpCache - Source code
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016
Thank you for your attention!
https://github.com/lisachenko
https://twitter.com/lisachenko

More Related Content

DOC
Hotel_Management_System_ANALYSIS_AND_DES.doc
PDF
The Four V's of Big Data - IBM Infographic
PPTX
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
ODP
Weaving aspects in PHP with the help of Go! AOP library
PPTX
Enterprise Symfony Architecture (RU)
PDF
CQRS and Event Sourcing in a Symfony application
PDF
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
PDF
Symfony Components
Hotel_Management_System_ANALYSIS_AND_DES.doc
The Four V's of Big Data - IBM Infographic
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Weaving aspects in PHP with the help of Go! AOP library
Enterprise Symfony Architecture (RU)
CQRS and Event Sourcing in a Symfony application
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Symfony Components

Viewers also liked (20)

PDF
Integrando React.js en aplicaciones Symfony (deSymfony 2016)
PDF
Keeping the frontend under control with Symfony and Webpack
PDF
Building a Node.JS accelerator for your headless Drupal backend - DrupalCamp ...
PDF
vert.x - life beyond jetty and apache
PDF
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
PPTX
SymfonyCon Berlin 2016 Jenkins Deployment Pipelines
PDF
MVP & Startup, with OpenSource Software and Microsoft Azure
PDF
Multi kernelowa aplikacja w oparciu o Symfony 3 i microkernele
PDF
Global Varnish Cluster with GeoDNS
PPTX
TV Commercials still rule in much of Asia - How effective is yours?
PDF
From * to Symfony2
PDF
SaaS con Symfony2
PPTX
Varnish - Cache mal was!
PDF
Scaling symfony apps
PDF
Symfony day 2016
PDF
PHP 7 et Symfony 3
PDF
Unit and Functional Testing with Symfony2
PDF
PHP High Availability High Performance
PDF
Getting your open source company to contribution
PDF
Nuvola: a tale of migration to AWS
Integrando React.js en aplicaciones Symfony (deSymfony 2016)
Keeping the frontend under control with Symfony and Webpack
Building a Node.JS accelerator for your headless Drupal backend - DrupalCamp ...
vert.x - life beyond jetty and apache
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
SymfonyCon Berlin 2016 Jenkins Deployment Pipelines
MVP & Startup, with OpenSource Software and Microsoft Azure
Multi kernelowa aplikacja w oparciu o Symfony 3 i microkernele
Global Varnish Cluster with GeoDNS
TV Commercials still rule in much of Asia - How effective is yours?
From * to Symfony2
SaaS con Symfony2
Varnish - Cache mal was!
Scaling symfony apps
Symfony day 2016
PHP 7 et Symfony 3
Unit and Functional Testing with Symfony2
PHP High Availability High Performance
Getting your open source company to contribution
Nuvola: a tale of migration to AWS
Ad

Similar to Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016 (20)

PPTX
Starting with varnish cache
ODP
PHP London Dec 2013 - Varnish - The 9 circles of hell
PDF
Speed up your site with Varnish
PPTX
Varnish –Http Accelerator
PDF
Varnish Cache - step by step
PDF
getting started with varnish
PDF
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
PDF
Going crazy with Varnish and Symfony
PPTX
Varnish, the high performance valhalla?
PDF
VUG5: Varnish at Opera Software
PPT
Varnish and Drupal- Accelerating Website Performance and Flexibility with Var...
PDF
Tips for going fast in a slow world: Michael May at OSCON 2015
PPTX
CI_CONF 2012: Scaling - Chris Miller
PPTX
CI_CONF 2012: Scaling
PDF
PDF
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PDF
Performance
PDF
OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...
ODP
Accelerate your web app with a layer of Varnish
PDF
Supercharging Content Delivery with Varnish
Starting with varnish cache
PHP London Dec 2013 - Varnish - The 9 circles of hell
Speed up your site with Varnish
Varnish –Http Accelerator
Varnish Cache - step by step
getting started with varnish
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Going crazy with Varnish and Symfony
Varnish, the high performance valhalla?
VUG5: Varnish at Opera Software
Varnish and Drupal- Accelerating Website Performance and Flexibility with Var...
Tips for going fast in a slow world: Michael May at OSCON 2015
CI_CONF 2012: Scaling - Chris Miller
CI_CONF 2012: Scaling
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
Performance
OSDC 2012 | Ultra-performant dynamic websites with Varnish by Dr. Chriatian W...
Accelerate your web app with a layer of Varnish
Supercharging Content Delivery with Varnish
Ad

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin 2016