SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Load Balancing and 
Scaling with NGINX 
Introduced by Andrew Alexeev 
Presented by Owen Garrett 
Nginx, Inc.
About this webinar 
When one server just isn’t enough, how can you scale out? In this 
webinar, you'll learn how to build out the capacity of your website. You'll 
see a variety of scalability approaches and some of the advanced 
capabilities of NGINX Plus.
INTRODUCING NGINX…
What is NGINX? 
Internet 
Proxy 
Caching, Load Balancing… HTTP traffic 
N 
Web Server 
Serve content from disk 
Application Server 
FastCGI, uWSGI, Passenger… 
Application Acceleration 
SSL and SPDY termination 
Performance Monitoring 
High Availability 
Advanced Features: Bandwidth Management 
Content-based Routing 
Request Manipulation 
Response Rewriting 
Authentication 
Video Delivery 
Mail Proxy 
GeoLocation
NGINX Accelerates 
143,000,000 
Websites
22% 
Top 1 million websites 37% 
Top 1,000 websites
NGINX and NGINX Plus 
NGINX F/OSS 
nginx.org 
3rd party 
modules 
Large community of >100 modules
NGINX and NGINX Plus 
NGINX F/OSS 
nginx.org 
3rd party 
modules 
Large community of >100 modules 
NGINX Plus 
Advanced load balancing features 
Ease-of-management 
Commercial support
WHY LOAD-BALANCE?
Load-balancing Web Servers 
Internet 
N 
 Improved Application Availability 
 Management 
 Increased Capacity 
 Advanced techniques e.g. A|B testing 
Why?  DNS Round Robin 
 Hardware L4 load balancer 
 Software Reverse Proxy LB 
 Cloud solution 
How?
Three Load Balancing case studies 
Basic Load Balancing with NGINX 
When you need more control 
Advanced techniques 
1 
2 
3
1. Basic Load Balancing 
• Simple scalability 
– All servers have same applications/services 
– Load-balancer extracts optimal performance
Basic load balancing 
server { 
listen 80; 
location / { 
proxy_pass http://backend; 
} 
} 
upstream backend { 
zone backend 64k; 
server webserver1:80; 
server webserver2:80; 
server webserver3:80; 
server webserver4:80; 
}
Basic load balancing 
• Use logging to debug: “$upstream_addr” 
log_format combined2 '$remote_addr - $remote_user [$time_local] ' 
'"$request" $status $body_bytes_sent ' 
'"$upstream_addr"'; 
192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 
192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.2:80" 
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.4:80" 
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.2:80" 
192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 
192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.4:80"
Basic Load Balancing 
• Round-robin is the default 
– Suitable for consistent pages 
• Least Connections 
– Suitable for varying pages 
• IP Hash 
– Fixed mapping, basic session 
persistence 
upstream backend { 
server webserver1:80; 
server webserver2:80; 
} 
upstream backend { 
least_conn; 
server webserver1:80; 
server webserver2:80; 
} 
upstream backend { 
ip_hash; 
server webserver1:80; 
server webserver2:80; 
}
Managing the Upstream Group 
• Direct config editing: 
– nginx –s reload 
– upstream.conf file: 
upstream backend { 
server webserver1:80; 
server webserver2:80; 
server webserver3:80; 
server webserver4:80; 
} 
• On-the-fly Reconfiguration [NGINX Plus only] 
$ curl 'http://localhost/upstream_conf?upstream=backend&id=3&down=1'
2. When you need more control… 
• In many scenarios, you want more control over 
where traffic is routed to: 
– Primary and secondary servers (aka master/slave) 
– Transaction state is accumulated on one server
‘Master’ and ‘Slave’ servers 
• Wordpress admin traffic (e.g. image uploads) 
Internet 
N 
‘Master’ 
‘Slave’ 
Copy image 
uploads from 
master to slave
‘Master’ and ‘Slave’ servers 
• Wordpress admin traffic (e.g. image uploads) 
N 
server { 
listen 80; 
location ~ ^/(wp-admin|wp-login) { 
proxy_pass http://wpadmin; 
} 
} 
upstream wpadmin { 
server server1:80; 
server server2:80 backup; 
} 
‘Master’ 
‘Slave’
Session Persistence [NGINX Plus only] 
• For when transaction state is accumulated on one server 
– Shopping carts 
– Advanced interactions 
– Non-RESTful Applications 
• NGINX Plus offers two methods: 
– sticky cookie 
– sticky route 
“Session persistence also 
helps performance”
Advanced Techniques 
• You can control load-balancing programmatically 
– A|B Testing 
– Migration between applications
A|B Testing 
Internet 
N 
‘backends’ upstream group 
Test 
server 
95% 
5% 
Partition traffic. 
Send 5% to new application instance
A|B Testing 
split_clients "${remote_addr}AAA" $servers { 
95% backends; 
5% 192.168.56.1:80; 
} 
server { 
listen 80; 
location / { 
proxy_pass http://$servers; 
} 
}
Application Migration 
Internet 
N 
‘backendsA’ upstream group 
‘backendsB’ upstream group 
Create new generation of application 
Migrate users from old to new 
Preserve sessions, no interruptions
Application Migration 
map $cookie_group $group { 
~(?P<value>.+)$ $value; 
default backendB; # The default upstream group 
} 
server { 
listen 80; 
location / { 
add_header Set-Cookie "group=$group; path=/" 
proxy_pass http://$group; 
} 
}
Three Load Balancing case studies 
Basic Load Balancing with NGINX 
When you need more control 
Advanced techniques 
1 
2 
3
Closing thoughts 
• 37% of the busiest websites use NGINX 
• Check out the load-balancing articles on 
nginx.com/blog 
• Future webinars: nginx.com/webinars 
Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)

Weitere ähnliche Inhalte

Was ist angesagt?

Nginx internals
Nginx internalsNginx internals
Nginx internals
liqiang xu
 

Was ist angesagt? (20)

Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to Nginx
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
 
Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web server
 
5 things you didn't know nginx could do
5 things you didn't know nginx could do5 things you didn't know nginx could do
5 things you didn't know nginx could do
 
Nginx internals
Nginx internalsNginx internals
Nginx internals
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content Cache
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Load Balancing with Nginx
Load Balancing with NginxLoad Balancing with Nginx
Load Balancing with Nginx
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Nginx Essential
Nginx EssentialNginx Essential
Nginx Essential
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
 
Web servers presentacion
Web servers presentacionWeb servers presentacion
Web servers presentacion
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
HAProxy
HAProxy HAProxy
HAProxy
 
Proxmox for DevOps
Proxmox for DevOpsProxmox for DevOps
Proxmox for DevOps
 
Benchmarking NGINX for Accuracy and Results
Benchmarking NGINX for Accuracy and ResultsBenchmarking NGINX for Accuracy and Results
Benchmarking NGINX for Accuracy and Results
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 

Ähnlich wie Load Balancing and Scaling with NGINX

Data power v7 update - Ravi Katikala
Data power v7 update - Ravi KatikalaData power v7 update - Ravi Katikala
Data power v7 update - Ravi Katikala
floridawusergroup
 

Ähnlich wie Load Balancing and Scaling with NGINX (20)

AWS as platform for scalable applications
AWS as platform for scalable applicationsAWS as platform for scalable applications
AWS as platform for scalable applications
 
What's new in NGINX Plus R19
What's new in NGINX Plus R19What's new in NGINX Plus R19
What's new in NGINX Plus R19
 
Data power v7 update - Ravi Katikala
Data power v7 update - Ravi KatikalaData power v7 update - Ravi Katikala
Data power v7 update - Ravi Katikala
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
Nginx Deep Dive Kubernetes Ingress
Nginx Deep Dive Kubernetes IngressNginx Deep Dive Kubernetes Ingress
Nginx Deep Dive Kubernetes Ingress
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
 
Deploying SharePoint @ Cloud
Deploying SharePoint @ CloudDeploying SharePoint @ Cloud
Deploying SharePoint @ Cloud
 
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
 
NGINX Plus R20 Webinar
NGINX Plus R20 WebinarNGINX Plus R20 Webinar
NGINX Plus R20 Webinar
 
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load Balancer
 
Architecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web APIArchitecting &Building Scalable Secure Web API
Architecting &Building Scalable Secure Web API
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
Managing and Scaling Puppet - PuppetConf 2014
Managing and Scaling Puppet - PuppetConf 2014Managing and Scaling Puppet - PuppetConf 2014
Managing and Scaling Puppet - PuppetConf 2014
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
WSO2 Application Server
WSO2 Application ServerWSO2 Application Server
WSO2 Application Server
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 

Mehr von NGINX, Inc.

How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptxHow to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 

Mehr von NGINX, Inc. (20)

【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
 
Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3
 
Managing Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & KubecostManaging Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & Kubecost
 
Manage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with ObservabilityManage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with Observability
 
Accelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with AutomationAccelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with Automation
 
Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesUnit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
 
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
 
Easily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINXEasily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINX
 
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
 
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINXKeep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
 
Protecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINXProtecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINX
 
NGINX Kubernetes API
NGINX Kubernetes APINGINX Kubernetes API
NGINX Kubernetes API
 
Successfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINXSuccessfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINX
 
Installing and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceInstalling and Configuring NGINX Open Source
Installing and Configuring NGINX Open Source
 
Shift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINXShift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINX
 
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptxHow to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Load Balancing and Scaling with NGINX

  • 1. Load Balancing and Scaling with NGINX Introduced by Andrew Alexeev Presented by Owen Garrett Nginx, Inc.
  • 2. About this webinar When one server just isn’t enough, how can you scale out? In this webinar, you'll learn how to build out the capacity of your website. You'll see a variety of scalability approaches and some of the advanced capabilities of NGINX Plus.
  • 4. What is NGINX? Internet Proxy Caching, Load Balancing… HTTP traffic N Web Server Serve content from disk Application Server FastCGI, uWSGI, Passenger… Application Acceleration SSL and SPDY termination Performance Monitoring High Availability Advanced Features: Bandwidth Management Content-based Routing Request Manipulation Response Rewriting Authentication Video Delivery Mail Proxy GeoLocation
  • 6. 22% Top 1 million websites 37% Top 1,000 websites
  • 7. NGINX and NGINX Plus NGINX F/OSS nginx.org 3rd party modules Large community of >100 modules
  • 8. NGINX and NGINX Plus NGINX F/OSS nginx.org 3rd party modules Large community of >100 modules NGINX Plus Advanced load balancing features Ease-of-management Commercial support
  • 10. Load-balancing Web Servers Internet N  Improved Application Availability  Management  Increased Capacity  Advanced techniques e.g. A|B testing Why?  DNS Round Robin  Hardware L4 load balancer  Software Reverse Proxy LB  Cloud solution How?
  • 11.
  • 12. Three Load Balancing case studies Basic Load Balancing with NGINX When you need more control Advanced techniques 1 2 3
  • 13. 1. Basic Load Balancing • Simple scalability – All servers have same applications/services – Load-balancer extracts optimal performance
  • 14. Basic load balancing server { listen 80; location / { proxy_pass http://backend; } } upstream backend { zone backend 64k; server webserver1:80; server webserver2:80; server webserver3:80; server webserver4:80; }
  • 15. Basic load balancing • Use logging to debug: “$upstream_addr” log_format combined2 '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$upstream_addr"'; 192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.2:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.4:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.2:80" 192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET /favicon.ico HTTP/1.1" 200 30 "127.0.1.4:80"
  • 16. Basic Load Balancing • Round-robin is the default – Suitable for consistent pages • Least Connections – Suitable for varying pages • IP Hash – Fixed mapping, basic session persistence upstream backend { server webserver1:80; server webserver2:80; } upstream backend { least_conn; server webserver1:80; server webserver2:80; } upstream backend { ip_hash; server webserver1:80; server webserver2:80; }
  • 17. Managing the Upstream Group • Direct config editing: – nginx –s reload – upstream.conf file: upstream backend { server webserver1:80; server webserver2:80; server webserver3:80; server webserver4:80; } • On-the-fly Reconfiguration [NGINX Plus only] $ curl 'http://localhost/upstream_conf?upstream=backend&id=3&down=1'
  • 18. 2. When you need more control… • In many scenarios, you want more control over where traffic is routed to: – Primary and secondary servers (aka master/slave) – Transaction state is accumulated on one server
  • 19. ‘Master’ and ‘Slave’ servers • Wordpress admin traffic (e.g. image uploads) Internet N ‘Master’ ‘Slave’ Copy image uploads from master to slave
  • 20. ‘Master’ and ‘Slave’ servers • Wordpress admin traffic (e.g. image uploads) N server { listen 80; location ~ ^/(wp-admin|wp-login) { proxy_pass http://wpadmin; } } upstream wpadmin { server server1:80; server server2:80 backup; } ‘Master’ ‘Slave’
  • 21. Session Persistence [NGINX Plus only] • For when transaction state is accumulated on one server – Shopping carts – Advanced interactions – Non-RESTful Applications • NGINX Plus offers two methods: – sticky cookie – sticky route “Session persistence also helps performance”
  • 22. Advanced Techniques • You can control load-balancing programmatically – A|B Testing – Migration between applications
  • 23. A|B Testing Internet N ‘backends’ upstream group Test server 95% 5% Partition traffic. Send 5% to new application instance
  • 24. A|B Testing split_clients "${remote_addr}AAA" $servers { 95% backends; 5% 192.168.56.1:80; } server { listen 80; location / { proxy_pass http://$servers; } }
  • 25. Application Migration Internet N ‘backendsA’ upstream group ‘backendsB’ upstream group Create new generation of application Migrate users from old to new Preserve sessions, no interruptions
  • 26. Application Migration map $cookie_group $group { ~(?P<value>.+)$ $value; default backendB; # The default upstream group } server { listen 80; location / { add_header Set-Cookie "group=$group; path=/" proxy_pass http://$group; } }
  • 27. Three Load Balancing case studies Basic Load Balancing with NGINX When you need more control Advanced techniques 1 2 3
  • 28. Closing thoughts • 37% of the busiest websites use NGINX • Check out the load-balancing articles on nginx.com/blog • Future webinars: nginx.com/webinars Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)

Hinweis der Redaktion

  1. Hook. Scaling a wordpress site… but principles can be applied to any web-based service
  2. As we go through this presentation, we’ll highlight some of the new features that are specific to nginx plus
  3. Hardware load balancer – L4 (or may be software) Partial TCP stack DSR, connection mirroring, failover very high performance (packets per second, syn cookies,…) example: F5 fasthttp (software). Warnings e.g. out of order packets most moving to a software reverse proxy approach Reverse proxy Full TCP stack
  4. Which discipline should I use? Round robin is simple, but sometimes has odd side effects Least connections is very effective at smoothing out loads IP Hash gives a simple session persistence effect but may not distribute load effectively Demo: round robin with the config above will appear to fail because we will get responses from server1 and 3 only. This is because the client makes a ‘silent’ request for favicon.ico too.
  5. On-the-fly reconfig… need a ‘zone’ in the upstream group
  6. In wordpress, it’s common to synchronize filesystems in one direction
  7. Example – image editing application, shopping cart