Tuning NGINX For High Performance - SCALE 19x 19x

Transcription

Tuning NGINXfor high performanceNick Shadrinnick@nginx.com

All linkson one org2#nginx #nginxconf

About me Nick Shadrin Product Manager at NGINX Based in San Francisco 16 years experience with web tech nick@nginx.com @shadrin https://shadrin.org3#nginx #nginxconf

Agenda A basic NGINX configuration NGINX performance optimizations: Operating system-level optimizations Networking-level optimizations NGINX core optimizations Conclusions and questions4#nginx #nginxconf

“ when I started NGINX,I focused on a very specificproblem – how to handlemore customers persingle server.”- Igor Sysoev, NGINX creator & our founderMORE INFORMATION AT NGINX.COM

About NGINX, Inc. Company founded in 2011, NGINX Plus started in 2013VC-backed by enterprise software industry leadersHQ in San Francisco, offices in US and Europe800 commercial customers120 employeesMORE INFORMATION AT NGINX.COM

Web Scale8#nginx #nginxconf

Architecture approach Design for scaling Segment microservices out Use caching and microcaching@shadrin nick@nginx.com

Basic NGINX placement10#nginx #nginxconf

Inside ok.org/en/nginx.html11#nginx #nginxconf

12#nginx #nginxconf

OS tuning net.core.somaxconn net.core.netdev max backlog net.ipv4.ip local port range sys.fs.file max /etc/security/limits.conf, nofile settingSee https://www.nginx.com/blog/tuning-nginx/13#nginx #nginxconf

Overcoming ephemeral port exhaustion Increase local port range Split traffic across multiple IPs NGINX since 1.11.2 usesIP BIND ADDRESS NO PORT socket option -ephemeral-port-exhaustion-nginx-plus/14#nginx #nginxconf

Minimal NGINX configurationevents {}http {server {listen 80;location / {proxy pass http://backend;}}upstream backend {server backend1.example.com:8080;server backend2.example.com:8080;}}15#nginx #nginxconf

NGINX Performance features16#nginx #nginxconf

NGINX Core features Use correct number of worker processes- auto- # of available CPU cores Increase worker connections Increase worker rlimit nofile17#nginx #nginxconf

NGINX Core Features (cont'd) Turn off accept mutex:accept mutex off; Turn on Sendfilesendfile on; Use thread pools if I/O needs offloading:aio ost-performance-9x/18#nginx #nginxconf

Changes with nginx 1.11.326 Jul 2016*) Change: now the "accept mutex" directive is turned off by default.[skip]http://nginx.org/en/CHANGES19#nginx #nginxconf

NGINX Core Features (cont'd) Turn off accept mutex:accept mutex off; Turn on Sendfilesendfile on; Use thread pools if I/O needs offloading:aio ost-performance-9x/20#nginx #nginxconf

HTTP Keep alive Keepalive connections allow to reuse the same TCPconnection for multiple HTTP requests. For HTTP/1.1, no need to define anything, it'senabled by default on the frontend. Keepalives provide major performance benefitwhen used over SSL/TLS connections.21#nginx #nginxconf

HTTP Keepalive: benchmark HTTPS with NO keepalive (worst setup) Plain HTTP HTTP/2 with SSL22#nginx #nginxconf

Title Text23#nginx #nginxconf

HTTP Keepalive Keepalive on the Frontend:keepalive requests 100;keepalive timeout 75s;24#nginx #nginxconf

HTTP Keepalive on the backendKeepalive on the Backend:server {location / {proxy pass http://backend;proxy http version 1.1;proxy set header Connection "";}}.upstream backend {server example.com;keepalive 32;}25#nginx #nginxconf

HTTP Caching Microcaching with aching-nginx/ Cache placement entstrategies-nginx-plus/26#nginx #nginxconf

HTTP/2 Introduced in 2015 as a standard Based on Google's SPDY Includes major changes compared to HTTP/1: Binary headers with HPACK Multiple streams Prioritization Server Push27#nginx #nginxconf

HTTP/2 benchmark NGINX 1.10.0 Ubuntu 16.04 Openssl 1.0.2 Chrome Web browser Measuring full page reload28#nginx #nginxconf

HTTP/2 vs HTTP/1/SSL, percentage performance increaseZZ

Some numbers 40ms / 50 objects:HTTP/1: 510msHTTP/2: 250ms200ms / 100 objects:HTTP/1: 4.0sHTTP/2: 1.1s@shadrin nick@nginx.com 2 times faster 4 times faster

Screenshot: 2016-08-23, caniuse.com31#nginx #nginxconf

Screenshot: 2017-03-05, caniuse.com32#nginx #nginxconf

33#nginx #nginxconf

34#nginx #nginxconf

Measure your results NGINX provides extensive logs with custom variables.Configure log format with: upstream response time request time upstream cache status NGINX has simple set of metrics with stub statusmodule. Configure stub status NGINX Plus provides more extensive metrics withExtended Status module NGINX Amplify is a free monitoring SaaS solution.35#nginx #nginxconf

Sign up at amplify.nginx.com36#nginx #nginxconf

Sign up at amplify.nginx.com37#nginx #nginxconf

Conclusions Plan for scalability early Tune low level operating system Configure Keepalive Configure caching Enable HTTP/2 Measure your results38#nginx #nginxconf

How to Contribute hg.nginx.org github.com/nginx nginx.org/mailman39#nginx #nginxconf

Thank YouAll links in one page:https://shadrin.org/talksTwitter: @shadrinnick@nginx.com40#nginx #nginxconf

04.03.2017 · Networking-level optimizations . Chrome Web browser Measuring full page reload 28 HTTP/2 benchmark. ZZ HTTP/2 vs HTTP/1/SSL, percentage performance increase. @shadrin nick@nginx.com Some numbers 40ms / 50 objects: HTTP/1: 510ms HTTP/2: 250ms 200ms / 100 objects: HTTP/1: 4.0s HTTP/2: 1.1s 2 times faster 4 times faster. 31 #nginx #nginxconf Screenshot: