Delivering High-Performance
Web Sites with NGINX
June 7, 2017
MORE INFORMATION AT
NGINX.COM
MORE INFORMATION AT
NGINX.COM
The average attention span of
a human being dropped from
12 seconds in 2000,
to 8.25 seconds in 2013.
http://www.statisticbrain.com/attention-span-statistics/
MORE INFORMATION AT
NGINX.COM
Why does Performance matter?
MORE INFORMATION AT
NGINX.COM
0
10,000
20,000
30,000
40,000
50,000
60,000
70,000
80,000
90,000
100,000
110,000
120,000
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
IP Traffic (PB/month)
MORE INFORMATION AT
NGINX.COM
0
20
40
60
80
100
120
0
500
1,000
1,500
2,000
2,500
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
Web Page Weight
Weight (kB)
Weight (objects)
MORE INFORMATION AT
NGINX.COM
0
2
4
6
8
10
12
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
Typical user wait time (seconds)
MORE INFORMATION AT
NGINX.COM
How are delays perceived by users?
0.1 s
0.25 s
1.0 s
10 s
Instantaneous: < 0.1 s
Typical reaction time: < 0.25 s
Concentration span: < 1.0 s
Attention span: < 10 s
source: Jacob Nielsen, Usability Engineering
MORE INFORMATION AT
NGINX.COM
Some tales from the field…
500ms delay 20% decrease in ad
clickthroughs
100ms delay 1% decrease in
revenue per customer
2.2s improvement 15% increase in
downloads
60% improvement 14% increase in
donations
MORE INFORMATION AT
NGINX.COM
Lab Benchmarks do not predict
real-world performance
MORE INFORMATION AT
NGINX.COM
Four Fallacies of Benchmarking
1. Benchmark tools may not count network errors, only successful
requests
• Sometimes they do count fast, application errors and this
skews the results!
2. A fast, local network eliminates the effects of slow connections
and packet loss
3. Desktop-class operating systems are not tuned for real-world
performance
4. Benchmark traffic does not resemble real-world traffic
MORE INFORMATION AT
NGINX.COM
1. I use benchmarking tool X because it gives better
(higher) results than Y?
2. It got 1,000 RPS in the lab, but it’s struggling to
get more than 100 RPS in production?
Have you ever heard…?
So, what is benchmarking
good for?
MORE INFORMATION AT
NGINX.COM
How can I reliably improve my
site performance?
MORE INFORMATION AT
NGINX.COM
Internet
4 opportunities to optimize performance
Python
Ruby
node.js
Java
Client Device Network Application Stack Code
MORE INFORMATION AT
NGINX.COM
Internet
Python
Ruby
node.js
Java
Client Device Network Code
Application Stack
4 opportunities to optimize performance
MORE INFORMATION AT
NGINX.COM
NGINX: Part of your Application Stack
NGINX Plus
Load Balancing
Tier
SSL decrypt
Internal Load Balancing
Groups of web and
application servers
Application Platform
Typical application stacks
are not optimized for
performance in the face of
unpredictable, slow
internet traffic.
NGINX and NGINX Plus
are optimized for real-
world traffic
MORE INFORMATION AT
NGINX.COM
NGINX: What makes NGINX different?
NGINX philosophy Alternative Products
Architecture Event driven
• Massively scalable
• No hard limit on concurrency
Process or thread per connection
• Each connection is expensive
• Fixed concurrency limit
Features Simple, lightweight
• Web server and cache
• Reverse proxy and load balancer
Rich, but heavyweight
• Web and application server
• High memory and CPU footprint
Purpose Application Acceleration
• Focus on performance first,
features second
Rich application server
• Focus on functionality and
developer productivity
MORE INFORMATION AT
NGINX.COM
How does NGINX help you?
MORE INFORMATION AT
NGINX.COM
NGINX: Three things it can do for your app
Offload HTTP “Heavy Lifting”
Cache common responses
Deliver secure content faster with HTTP/2
MORE INFORMATION AT
NGINX.COM
What is HTTP heavy lifting?
Hundreds of
concurrent
connections…
require hundreds of heavyweight
threads or processes…
competing for limited
CPU and memory
Client-side:
Slow network
Multiple connections
HTTP Keepalives
Server-side:
Limited concurrency
MORE INFORMATION AT
NGINX.COM
What is HTTP heavy lifting?
Hundreds of
concurrent
connections…
handed by a small number of
multiplexing processes,…
typically one process
per core
MORE INFORMATION AT
NGINX.COM
Let’s see the effect on a typical web app
SlowHTTPTest
code.google.com/p/slowhttptest/
WordPress
Standard install
:80
Measure capacity of application using a simple benchmarking tool (ab)
Repeat the test after using slowhttptest to simulate a number of slow internet users
MORE INFORMATION AT
NGINX.COM
Repeat, using NGINX to do the heavy
lifting
Measure capacity of application using a simple benchmarking tool (ab)
Repeat the test after using slowhttptest to simulate a number of slow internet users
SlowHTTPTest
code.google.com/p/slowhttptest/
NGINX+ and WordPress
Standard install with sample
content
:8080
MORE INFORMATION AT
NGINX.COM
How did we do this?
server {
listen 8080;
location / {
proxy_pass http://wp-servers;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
upstream wp-servers {
server localhost:80;
keepalive 10;
}
Listen for traffic on port 8080
Pass it to the wp-servers
upstream group, while upgrading
the internal connection to
HTTP/1.1 keepalives
Load-balance to one server –
localhost:80 – and maintain a
maximum of 10 idle keepalive
connections
MORE INFORMATION AT
NGINX.COM
NGINX: Three things it can do for your app
Offload HTTP “Heavy Lifting”
Cache common responses
Deliver secure content faster with HTTP/2
MORE INFORMATION AT
NGINX.COM
What is the purpose of caching?
MORE INFORMATION AT
NGINX.COM
Let’s see it in action
Measure capacity of application using a simple benchmarking tool (ab)
Compare with and without caching
ab
Measure performance difference
NGINX+ (caching) and WordPress
Standard install
:8082
MORE INFORMATION AT
NGINX.COM
How did we do this?
proxy_cache_path /tmp/cache
keys_zone=cache:10m levels=1:2
inactive=600s max_size=100m;
server {
listen 8082;
location / {
proxy_pass http://wp-servers;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_cache cache;
proxy_cache_valid 200 1s;
proxy_cache_lock on;
proxy_cache_use_stale updating;
}
}
Configure a local disk/memory
cache
Listen on port 8082
Proxy all traffic to wp-servers
Cache responses for 1 second,
and update in the background
MORE INFORMATION AT
NGINX.COM
NGINX: Three things it can do for your app
Offload HTTP “Heavy Lifting”
Cache common responses
Deliver secure content faster with HTTP/2
MORE INFORMATION AT
NGINX.COM
HTTP/1 connection HTTP/2 connection
MORE INFORMATION AT
NGINX.COM
HTTP/1.x and HTTP/2 Compared
Browsers typically makes 6 connections per domain with HTTP/1.x
MORE INFORMATION AT
NGINX.COM
HTTP/1 waterfall HTTP/2 waterfall
MORE INFORMATION AT
NGINX.COM
Use of HTTP/2
Source: https://w3techs.com/technologies/breakdown/ce-http2/ranking
MORE INFORMATION AT
NGINX.COM
Use of HTTP/2
Source: https://w3techs.com/technologies/segmentation/ce-http2/web_server
MORE INFORMATION AT
NGINX.COM
HTTP/2: Summary of Features
• Request Multiplexing – multiple, parallel requests in the same TCP connection
• Binary Header – Smaller header size
• Request Prioritization – Define what objects should be prioritized
• Header Compression – HPACK header compression reduces size of HTTP/2
header
• Mandatory SSL – Not mandated by RFC but Chrome and Firefox won’t support
without it
• More secure websites
• Higher search rankings for encrypted sites
MORE INFORMATION AT
NGINX.COM
Typical HTTP/2 configuration
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
ssl_certificate server.crt;
ssl_certificate_key server.key;
…
}
Capture and redirect HTTP traffic
to HTTPS
Enable http2 with the http2
keyword
MORE INFORMATION AT
NGINX.COM
Conclusion
MORE INFORMATION AT
NGINX.COM
MORE INFORMATION AT
NGINX.COM
NGINX: Three things it can do for your app
Offload HTTP “Heavy Lifting”
Cache common responses
Deliver secure content faster with HTTP/2
MORE INFORMATION AT
NGINX.COM
NGINX open source
NGINX
reverse
proxy
• Rules Language
• Rate Limits
• Access Control
• Proxying and Balancing
• Logging
• Caching
• Direct response
HTTP
HTTPS
HTTP/2
TCP
UDP
MORE INFORMATION AT
NGINX.COM
NGINX Plus
NGINX
Plus
• Rules Language
• Rate Limits
• Access Control
• Proxying and Balancing
• Logging
• Adv. Load Balancing
• Web App Firewall
• Service Discovery
• Authentication
• Load Balancing Config API
• Extended Status API
• Caching and Purging
• Direct response
HTTP
HTTPS
HTTP/2
TCP
UDP
MORE INFORMATION AT
NGINX.COM
Where to find more?
Past webinars: nginx.com/webinars
NGINX Trial: nginx.com
Questions – Q&A panel in webex
Thank you

Delivering High Performance Websites with NGINX