SlideShare a Scribd company logo
Scaling Varnish to Handle One Million Vhosts
Nathan Moore
MaxCDN acquired by StackPath in 2016
• https://techcrunch.com/2016/07/25/security-as-a-service-
startup-stackpath-nabs-180m-4-acquisitions-including-maxcdn/
9/21/16 2
Content Delivery Networks – CDN FAQ
9/21/16 3
CDN is a global web proxy
9/21/16 4
CDN is a caching global web proxy
9/21/16 5
CDN is a caching global web proxy for a million
VHosts
9/21/16 6
CDN has a HTTP object routing problem
• How does CDN proxy for a million VHosts?
9/21/16 7
Routing decisions based on HOST header
• Classic VCL
If (req.http.host == “www.foo.com”) {
set req.backend_hint = fooOrigin;
} else if (req.http.host == “www.bar.com”) {
set req.backend_hint = barOrigin;
} …
9/21/16 8
Classic VCL with if…then statements
• Require 1 million “if else” statements
• varnish reload times excessive
• Must recompile VCL to reload dynamically
• If latency to recompile VCL is large, can exceed reload timeout
9/21/16 9
Quick benchmark
• Executed on local laptop in a single CPU VM to emphasize
latency difference.
• Using h2load run locally to request a 100B object
• h2load -n 50000 -c 1 -m 1 --h1 http://h1.netdna-dev.com:6081
• Directly to origin on localhost:
9/21/16 10
Quick benchmark
• Through Varnish and its if…then statements (only 2500 in this
case!)
9/21/16 11
Quick benchmark
• Through Varnish and its if…then statements (only 3 in this
case!)
9/21/16 12
Enter vmod_kvstore
• A general key-value store featuring O(1) lookups
• In-memory hash
• For this use case, HTTP object routing:
• HOST header is the key
• Backend server is the value
9/21/16 13
vmod_kvstore
• Old VCL:
If (req.http.host == “www.foo.com”) {
set req.backend_hint = fooOrigin;
} else if (req.http.host == “www.bar.com”) {
set req.backend_hint = barOrigin;
} …
9/21/16 14
vmod_kvstore
• New VCL:
Set req.http.backend_name =
kvstore.get(0,req.http.Host,“defaultBackendName”);
If (req.http.backend_name == “myBackend1”) {
set req.backend_hint = myBackend1;
} else {
set req.backend_hint = defaultBackendName;
}
9/21/16 15
Quick benchmark, updated
• Through Varnish and vmod_kvstore defining 20000 VHosts
9/21/16 16
vmod_kvstore
• Getter
• kvstore.get(unique kvstore number, key, default value)
• Can have multiple kvstores, each referred to by a unique number
• Default value is returned if key is not in the kvstore keyspace
• Setter
• kvstore.set(unique kvstore number, key, value, ttl)
• This sets a key->value pair
• The ttl is a time-to-live in seconds
• kvstore can be used to store temporary data
9/21/16 17
vmod_kvstore bulk create
• kvstore.init_file(unique kvstore number, number of buckets,
path to file, delimiter)
• Predefined file consists of
• req.http.Host -> req.backend_hint name values
9/21/16 18
vmod_kvstore dynamic update
• Setter method allows dynamic update of kvstore
• Use case:
• Could use HTTP GET request with custom header to allow dynamic
updating
If (req.http.X-Value-AddToKvstore) {
kvstore.set(0,req.http.Host,req.http.X-Value-AddToKvstore,0);
}
9/21/16 19
More vmod_kvstore use cases
• Map multiple aliases to a Vhost
kvstore.set(0, ”content.foo.com”, ”fooVhost”);
kvstore.set(0, ”static.foo.com”, ”fooVhost”);
kvstore.set(0, ”fooVHost”, ”fooBackendHint”);
• Now, workflow is:
req.http.X-VHost = kvstore.get(0, req.http.Host, ”defaultVHost”);
req.http.X-Backend = kvstore.get(0, req.http.X-Vhost,
“defaultBackend”);
If (req.http.X-Backend == ”fooBackendHint”) {
set req.backend_hint = fooBackendHint;
}
9/21/16 20
More vmod_kvstore use cases
• Override caching time on a per-VHost basis
kvstore.set(0, ”www.foo.com”, ”fooVHost”);
kvstore.set(0, “fooVHost.cacheTime”, ”30s”);
• Now, workflow is:
req.http.X-VHost = kvstore.get(0, req.http.Host, ”defaultVHost”);
set beresp.ttl = kvstore.get(0, req.http.X-VHost + “.cacheTime”,
”3600s”);
9/21/16 21
Conclusions
• As more logic is pulled into Varnish, more is asked of Vcl
• Make dynamic decisions based on any property of an HTTP object
• Persist state within kvstore through loading from file
• Dynamically update state within kvstore in-memory
• Scale ability to make decisions across millions of possible keys and
values
• Gain flexibility in implementation
9/21/16 22
Questions?
9/21/16 23
Appendix
9/21/16 24
Partitioning backend servers
• Can always pass through multiple proxies
9/21/16 25
Partitioning backend servers
9/21/16 26
Partitioning backend servers with Origin Shield
9/21/16 27

More Related Content

PDF
CEPH DAY BERLIN - UNLIMITED FILESERVER WITH SAMBA CTDB AND CEPHFS
PDF
Deploying pNFS over Distributed File Storage w/ Jiffin Tony Thottan and Niels...
ODP
Disaster Recovery in oVirt
PDF
CEPH DAY BERLIN - CEPH MANAGEMENT THE EASY AND RELIABLE WAY
ODP
Accessing gluster ufo_-_eco_willson
PDF
Hyperconverged Cloud, Not just a toy anymore - Andrew Hatfield, Red Hat
PDF
Integration of Glusterfs in to commvault simpana
PDF
Arbiter volumes in gluster
CEPH DAY BERLIN - UNLIMITED FILESERVER WITH SAMBA CTDB AND CEPHFS
Deploying pNFS over Distributed File Storage w/ Jiffin Tony Thottan and Niels...
Disaster Recovery in oVirt
CEPH DAY BERLIN - CEPH MANAGEMENT THE EASY AND RELIABLE WAY
Accessing gluster ufo_-_eco_willson
Hyperconverged Cloud, Not just a toy anymore - Andrew Hatfield, Red Hat
Integration of Glusterfs in to commvault simpana
Arbiter volumes in gluster

What's hot (20)

PDF
Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...
ODP
oVirt DR Site to-site using ansible
PDF
NVMe over Fabrics and Composable Infrastructure - What Do They Mean for Softw...
PDF
Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)
PDF
Gluster as Block Store in Containers
PDF
What's New with Ceph - Ceph Day Silicon Valley
PDF
Integrating gluster fs,_qemu_and_ovirt-vijay_bellur-linuxcon_eu_2013
PDF
Boosting I/O Performance with KVM io_uring
PDF
Red Hat Gluster Storage
ODP
Introduction to highly_availablenfs_server_on_scale-out_storage_systems_based...
PDF
GFProxy: Scaling the GlusterFS FUSE Client
PPTX
Application_Benchmark_into_Virtualization
PPTX
Your 1st Ceph cluster
ODP
GlusterFS Cinder integration presented at GlusterNight Paris event @ Openstac...
ODP
Red Hat Gluster Storage : GlusterFS
PDF
CEPH DAY BERLIN - WHAT'S NEW IN CEPH
PDF
Ceph Research at UCSC
PDF
Red Hat Enterprise Linux: Open, hyperconverged infrastructure
ODP
Integrating gluster fs,_qemu_and_ovirt-vijay_bellur-linuxcon_eu_2013
PDF
Container Security via Monitoring and Orchestration - Container Security Summit
Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...
oVirt DR Site to-site using ansible
NVMe over Fabrics and Composable Infrastructure - What Do They Mean for Softw...
Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)
Gluster as Block Store in Containers
What's New with Ceph - Ceph Day Silicon Valley
Integrating gluster fs,_qemu_and_ovirt-vijay_bellur-linuxcon_eu_2013
Boosting I/O Performance with KVM io_uring
Red Hat Gluster Storage
Introduction to highly_availablenfs_server_on_scale-out_storage_systems_based...
GFProxy: Scaling the GlusterFS FUSE Client
Application_Benchmark_into_Virtualization
Your 1st Ceph cluster
GlusterFS Cinder integration presented at GlusterNight Paris event @ Openstac...
Red Hat Gluster Storage : GlusterFS
CEPH DAY BERLIN - WHAT'S NEW IN CEPH
Ceph Research at UCSC
Red Hat Enterprise Linux: Open, hyperconverged infrastructure
Integrating gluster fs,_qemu_and_ovirt-vijay_bellur-linuxcon_eu_2013
Container Security via Monitoring and Orchestration - Container Security Summit
Ad

Similar to Stackpath use case (20)

PDF
Supercharging Content Delivery with Varnish
PPTX
Varnish extend
PDF
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PPTX
Varnish –Http Accelerator
PDF
Varnish Cache
PDF
Become Happier by using Varnish Cache
PDF
Varnish in action phpday2011
PDF
VUG5: Varnish at Opera Software
PPTX
cache concepts and varnish-cache
PDF
Tips for going fast in a slow world: Michael May at OSCON 2015
PDF
Performance
PDF
Caching with Varnish
PDF
Build your own CDN with Varnish - Confoo 2022
PPTX
June8 presentation
PPTX
CI_CONF 2012: Scaling - Chris Miller
PPTX
CI_CONF 2012: Scaling
ODP
Accelerate your web app with a layer of Varnish
PDF
Varnish Cache Plus. Random notes for wise web developers
PDF
Varnish
PDF
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
Supercharging Content Delivery with Varnish
Varnish extend
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
Varnish –Http Accelerator
Varnish Cache
Become Happier by using Varnish Cache
Varnish in action phpday2011
VUG5: Varnish at Opera Software
cache concepts and varnish-cache
Tips for going fast in a slow world: Michael May at OSCON 2015
Performance
Caching with Varnish
Build your own CDN with Varnish - Confoo 2022
June8 presentation
CI_CONF 2012: Scaling - Chris Miller
CI_CONF 2012: Scaling
Accelerate your web app with a layer of Varnish
Varnish Cache Plus. Random notes for wise web developers
Varnish
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
Ad

More from Varnish Software (20)

PDF
Ask Me Anything on authentication & authorisation in Varnish
PDF
Boozt.com Use Case
PPTX
Akamai connector for varnish
PPTX
Varnish High Availability
PDF
PostNord: Copy On Write
PDF
Streaming with Varnish
PPTX
Edgestash
PPTX
What is new in varnish plus
PDF
Varnish Extend demo
PDF
Varnish extend introduction
PDF
Cedexis introduction
PDF
Secure content caching
PDF
Microservices
PDF
Varnishtest
PDF
Lightning fast with Varnish
PDF
E-commerce use case
PDF
Access control
PPTX
Varnish TLS
PPTX
Debugging varnish
Ask Me Anything on authentication & authorisation in Varnish
Boozt.com Use Case
Akamai connector for varnish
Varnish High Availability
PostNord: Copy On Write
Streaming with Varnish
Edgestash
What is new in varnish plus
Varnish Extend demo
Varnish extend introduction
Cedexis introduction
Secure content caching
Microservices
Varnishtest
Lightning fast with Varnish
E-commerce use case
Access control
Varnish TLS
Debugging varnish

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Machine Learning_overview_presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25-Week II
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
sap open course for s4hana steps from ECC to s4
Machine Learning_overview_presentation.pptx

Stackpath use case

  • 1. Scaling Varnish to Handle One Million Vhosts Nathan Moore
  • 2. MaxCDN acquired by StackPath in 2016 • https://techcrunch.com/2016/07/25/security-as-a-service- startup-stackpath-nabs-180m-4-acquisitions-including-maxcdn/ 9/21/16 2
  • 3. Content Delivery Networks – CDN FAQ 9/21/16 3
  • 4. CDN is a global web proxy 9/21/16 4
  • 5. CDN is a caching global web proxy 9/21/16 5
  • 6. CDN is a caching global web proxy for a million VHosts 9/21/16 6
  • 7. CDN has a HTTP object routing problem • How does CDN proxy for a million VHosts? 9/21/16 7
  • 8. Routing decisions based on HOST header • Classic VCL If (req.http.host == “www.foo.com”) { set req.backend_hint = fooOrigin; } else if (req.http.host == “www.bar.com”) { set req.backend_hint = barOrigin; } … 9/21/16 8
  • 9. Classic VCL with if…then statements • Require 1 million “if else” statements • varnish reload times excessive • Must recompile VCL to reload dynamically • If latency to recompile VCL is large, can exceed reload timeout 9/21/16 9
  • 10. Quick benchmark • Executed on local laptop in a single CPU VM to emphasize latency difference. • Using h2load run locally to request a 100B object • h2load -n 50000 -c 1 -m 1 --h1 http://h1.netdna-dev.com:6081 • Directly to origin on localhost: 9/21/16 10
  • 11. Quick benchmark • Through Varnish and its if…then statements (only 2500 in this case!) 9/21/16 11
  • 12. Quick benchmark • Through Varnish and its if…then statements (only 3 in this case!) 9/21/16 12
  • 13. Enter vmod_kvstore • A general key-value store featuring O(1) lookups • In-memory hash • For this use case, HTTP object routing: • HOST header is the key • Backend server is the value 9/21/16 13
  • 14. vmod_kvstore • Old VCL: If (req.http.host == “www.foo.com”) { set req.backend_hint = fooOrigin; } else if (req.http.host == “www.bar.com”) { set req.backend_hint = barOrigin; } … 9/21/16 14
  • 15. vmod_kvstore • New VCL: Set req.http.backend_name = kvstore.get(0,req.http.Host,“defaultBackendName”); If (req.http.backend_name == “myBackend1”) { set req.backend_hint = myBackend1; } else { set req.backend_hint = defaultBackendName; } 9/21/16 15
  • 16. Quick benchmark, updated • Through Varnish and vmod_kvstore defining 20000 VHosts 9/21/16 16
  • 17. vmod_kvstore • Getter • kvstore.get(unique kvstore number, key, default value) • Can have multiple kvstores, each referred to by a unique number • Default value is returned if key is not in the kvstore keyspace • Setter • kvstore.set(unique kvstore number, key, value, ttl) • This sets a key->value pair • The ttl is a time-to-live in seconds • kvstore can be used to store temporary data 9/21/16 17
  • 18. vmod_kvstore bulk create • kvstore.init_file(unique kvstore number, number of buckets, path to file, delimiter) • Predefined file consists of • req.http.Host -> req.backend_hint name values 9/21/16 18
  • 19. vmod_kvstore dynamic update • Setter method allows dynamic update of kvstore • Use case: • Could use HTTP GET request with custom header to allow dynamic updating If (req.http.X-Value-AddToKvstore) { kvstore.set(0,req.http.Host,req.http.X-Value-AddToKvstore,0); } 9/21/16 19
  • 20. More vmod_kvstore use cases • Map multiple aliases to a Vhost kvstore.set(0, ”content.foo.com”, ”fooVhost”); kvstore.set(0, ”static.foo.com”, ”fooVhost”); kvstore.set(0, ”fooVHost”, ”fooBackendHint”); • Now, workflow is: req.http.X-VHost = kvstore.get(0, req.http.Host, ”defaultVHost”); req.http.X-Backend = kvstore.get(0, req.http.X-Vhost, “defaultBackend”); If (req.http.X-Backend == ”fooBackendHint”) { set req.backend_hint = fooBackendHint; } 9/21/16 20
  • 21. More vmod_kvstore use cases • Override caching time on a per-VHost basis kvstore.set(0, ”www.foo.com”, ”fooVHost”); kvstore.set(0, “fooVHost.cacheTime”, ”30s”); • Now, workflow is: req.http.X-VHost = kvstore.get(0, req.http.Host, ”defaultVHost”); set beresp.ttl = kvstore.get(0, req.http.X-VHost + “.cacheTime”, ”3600s”); 9/21/16 21
  • 22. Conclusions • As more logic is pulled into Varnish, more is asked of Vcl • Make dynamic decisions based on any property of an HTTP object • Persist state within kvstore through loading from file • Dynamically update state within kvstore in-memory • Scale ability to make decisions across millions of possible keys and values • Gain flexibility in implementation 9/21/16 22
  • 25. Partitioning backend servers • Can always pass through multiple proxies 9/21/16 25
  • 27. Partitioning backend servers with Origin Shield 9/21/16 27