SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Load Balancing
     with Apache
   Bradley Holt (http://bradley-holt.com/)
@BradleyHolt (http://twitter.com/BradleyHolt)
About Me
Co-Founder and
Technical Director
Contributor
Author




         http://oreilly.com/catalog/9781449303129/   http://oreilly.com/catalog/9781449303433/
Apache HTTP Server
About Apache
Open source

Serves over 100 million websites

Can run in many different modes, depending on your needs,
via MultiProcessing Modules (MPMs)

The Apache Software Foundation (ASF) supports many other
open source software projects
Alternatives
Software Load Balancers
HAProxy

Varnish

Pound

Perlbal

Squid

nginx

Linux-HA (High-Availability Linux) on Linux Standard Base (LSB)
Hosted Load Balancers
Amazon’s Elastic Load Balancing

Rackspace Cloud Load Balancers
Shared Nothing Architecture (SN)
Properties of a SN System
Each node operates independently

No single point of contention

PHP is shared nothing by default…
Breaking SN
Sessions require sharing (or require the use of sticky sessions)

Databases are the most common single point of contention
(this is why eventual consistency is important)

Storing variables in memory between requests breaks SN
(possible in Java and .NET)
Practical SN Techniques
Store sessions in a memcached cluster—this makes web nodes SN

For database applications:
  • send writes to a write-only master
  • replicate to multiple read-only nodes
  • read-only nodes are now effectively SN
Clustering/partitioning/sharding can help, too (but painful).

Alternatively, use a “NoSQL” database (e.g. CouchDB is SN).
Load Balancing Examples
Required Modules
mod_proxy

mod_proxy_http (assuming you’re load balancing HTTP requests)

mod_proxy_balancer

mod_headers (for sticky sessions)

mod_rewrite (for advanced con gurations)
Basic Load Balancing
# Create a load balancer named "web-nodes"
<Proxy balancer://web-nodes>
    # Add three load balancer members
    BalancerMember http://www1.example.com
    BalancerMember http://www2.example.com
    BalancerMember http://www3.example.com
</Proxy>
# Send all requests to the "web-nodes" balancer
ProxyPass / balancer://web-nodes
Apache allows traffic to be
balanced by number of requests
(lbmethod=byrequests), bytes
transferred (lbmethod=bytraffic),
or by the number of currently pending
requests (lbmethod=bybusyness).
Sticky Sessions in PHP
(your mileage may vary)
# Create a load balancer named "web-nodes"
<Proxy balancer://web-nodes>
    # Add three load balancer members
    BalancerMember http://www1.example.com
    BalancerMember http://www2.example.com
    BalancerMember http://www3.example.com
    # Use the PHPSESSID for sticky sessions
    ProxySet stickysession=PHPSESSID
</Proxy>
# Send all requests to the "web-nodes" balancer
ProxyPass / balancer://web-nodes
Create Your Own Sticky Sessions
# Set a cookie
Header add Set-Cookie 
"NODE=%{BALANCER_WORKER_ROUTE}e; path=/" 
env=BALANCER_ROUTE_CHANGED
# Create a load balancer named "web-nodes"
<Proxy balancer://web-nodes>
    # Add three load balancer members
    BalancerMember http://www1.example.com route=1
    BalancerMember http://www2.example.com route=2
    BalancerMember http://www3.example.com route=3
    # Use the NODE cookie for sticky sessions
    ProxySet stickysession=NODE
</Proxy>
# Send all requests to the "web-nodes" balancer
ProxyPass / balancer://web-nodes
Use a private network to connect your
load balancer to your balancer
members.

This allows for dedicated bandwidth
and opens up the possibility of
offloading SSL handling to the load
balancer.
Route Based on HTTP Method
# Enable mod_rewrite
RewriteEngine On

# Send POST, PUT, and DELETEs to "write" balancer
RewriteCond %{REQUEST_METHOD} ^(POST|PUT|DELETE)$
RewriteRule ^/(.*)$ balancer://write$1 [P]

# Send GET, HEAD, and OPTIONS to "read" balancer
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$
RewriteRule ^/(.*)$ balancer://read$1 [P]

# Modify HTTP response headers (e.g. Location)
ProxyPassReverse / balancer://write
ProxyPassReverse / balancer://read
Consider con guring multiple load
balancers, removing the load balancer
as a single point of failure.

This typically involves having two or
more load balancers sharing the same
IP address, with one con gured as a
failover.
Distributed Load Testing with Tsung
Tsung
Distributes load testing across multiple testing clients

Can generate huge numbers of concurrent users

Monitors CPU, memory, load, and network traffic

Simulates dynamic sessions, as described in a con guration le

Randomizes traffic patterns based on de ned probabilities

Recording and playback of sessions

HTML reports and graphs
XML Con guration File
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
  <!-- … -->
</tsung>
Client Side Setup
<!-- Client side setup -->
<clients>
  <client
     host="test-a"
     weight="1"
     maxusers="10000"
     cpu="4"
  />
  <client
     host="test-b"
     weight="1"
     maxusers="10000"
     cpu="4"
  />
</clients>
Server Side Setup
<!-- Server side setup -->
<servers>
  <server
     host="www"
     port="80"
     type="tcp"
  />
</servers>
Load Setup
<!-- Load setup -->
<load>
  <arrivalphase
    phase="1"
    duration="5"
    unit="minute"
  >
    <users
       arrivalrate="200"
       unit="second"
    />
  </arrivalphase>
</load>
Session Setup
<!-- Session setup -->
<session
  name="default"
  probability="100"
  type="ts_http"
>
  <thinktime
     value="1"
     random="true"
  />
  <request>
     <http
       method="GET"
       url="/"
       />
  </request>
</session>
Monitoring Setup
Tsung allows for monitoring
using Erlang, SNMP, or Munin
<!-- Monitoring setup -->
<monitoring>
  <monitor host="www" type="munin" />
  <monitor host="www1" type="munin" />
  <monitor host="www2" type="munin" />
  <monitor host="www3" type="munin" />
</monitoring>
Reports
From Scaling CouchDB by Bradley Holt (O’Reilly). Copyright 2011 Bradley Holt, 978-1-449-30343-3
Graphs
From Scaling CouchDB by Bradley Holt (O’Reilly). Copyright 2011 Bradley Holt, 978-1-449-30343-3
Questions?
Thank You
                Bradley Holt (http://bradley-holt.com/)
             @BradleyHolt (http://twitter.com/BradleyHolt)




Copyright © 2011 Bradley Holt. All rights reserved.

Weitere ähnliche Inhalte

Was ist angesagt?

Easy, scalable, fault tolerant stream processing with structured streaming - ...
Easy, scalable, fault tolerant stream processing with structured streaming - ...Easy, scalable, fault tolerant stream processing with structured streaming - ...
Easy, scalable, fault tolerant stream processing with structured streaming - ...
Databricks
 
OpenSearch
OpenSearchOpenSearch
OpenSearch
hchen1
 

Was ist angesagt? (20)

Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafka
 
Azure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDBAzure Database Services for MySQL PostgreSQL and MariaDB
Azure Database Services for MySQL PostgreSQL and MariaDB
 
Kubernetes and Prometheus
Kubernetes and PrometheusKubernetes and Prometheus
Kubernetes and Prometheus
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Hashicorp Corporate Pitch Deck Stenio_v2
Hashicorp Corporate Pitch Deck Stenio_v2 Hashicorp Corporate Pitch Deck Stenio_v2
Hashicorp Corporate Pitch Deck Stenio_v2
 
From Zero to Hero with Kafka Connect (Robin Moffat, Confluent) Kafka Summit L...
From Zero to Hero with Kafka Connect (Robin Moffat, Confluent) Kafka Summit L...From Zero to Hero with Kafka Connect (Robin Moffat, Confluent) Kafka Summit L...
From Zero to Hero with Kafka Connect (Robin Moffat, Confluent) Kafka Summit L...
 
Building flexible ETL pipelines with Apache Camel on Quarkus
Building flexible ETL pipelines with Apache Camel on QuarkusBuilding flexible ETL pipelines with Apache Camel on Quarkus
Building flexible ETL pipelines with Apache Camel on Quarkus
 
Easy, scalable, fault tolerant stream processing with structured streaming - ...
Easy, scalable, fault tolerant stream processing with structured streaming - ...Easy, scalable, fault tolerant stream processing with structured streaming - ...
Easy, scalable, fault tolerant stream processing with structured streaming - ...
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure Databricks
 
Distributed applications using Hazelcast
Distributed applications using HazelcastDistributed applications using Hazelcast
Distributed applications using Hazelcast
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
AWS Glue - let's get stuck in!
AWS Glue - let's get stuck in!AWS Glue - let's get stuck in!
AWS Glue - let's get stuck in!
 
Kafka Connect - debezium
Kafka Connect - debeziumKafka Connect - debezium
Kafka Connect - debezium
 
How Adobe uses Structured Streaming at Scale
How Adobe uses Structured Streaming at ScaleHow Adobe uses Structured Streaming at Scale
How Adobe uses Structured Streaming at Scale
 
OpenSearch
OpenSearchOpenSearch
OpenSearch
 
Introduction to Apache solr
Introduction to Apache solrIntroduction to Apache solr
Introduction to Apache solr
 
Kafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsKafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and Ops
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practices
 
삼성전자 5G Core CNF를 위한 클라우드 여정 이야기 - 최우형 AWS 솔루션즈 아키텍트 / 구동영 프로, 삼성전자 :: AWS Su...
삼성전자 5G Core CNF를 위한 클라우드 여정 이야기 - 최우형 AWS 솔루션즈 아키텍트 / 구동영 프로, 삼성전자 :: AWS Su...삼성전자 5G Core CNF를 위한 클라우드 여정 이야기 - 최우형 AWS 솔루션즈 아키텍트 / 구동영 프로, 삼성전자 :: AWS Su...
삼성전자 5G Core CNF를 위한 클라우드 여정 이야기 - 최우형 AWS 솔루션즈 아키텍트 / 구동영 프로, 삼성전자 :: AWS Su...
 

Andere mochten auch

Scaling Your Web Application
Scaling Your Web ApplicationScaling Your Web Application
Scaling Your Web Application
Ketan Deshmukh
 
Load & Performance TESTING
Load & Performance TESTINGLoad & Performance TESTING
Load & Performance TESTING
Guido Serra
 
Tsung Intro presentation 2013
Tsung Intro presentation 2013Tsung Intro presentation 2013
Tsung Intro presentation 2013
Steffen Larsen
 

Andere mochten auch (20)

Cấu hình network load balancing trên windows server 2008
Cấu hình network load balancing trên windows server 2008Cấu hình network load balancing trên windows server 2008
Cấu hình network load balancing trên windows server 2008
 
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Apache HTTPD 2.4 Reverse Proxy: The Hidden GemApache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
 
Scaling Your Web Application
Scaling Your Web ApplicationScaling Your Web Application
Scaling Your Web Application
 
Scaling your web app with MySQL replication
Scaling your web app with MySQL replicationScaling your web app with MySQL replication
Scaling your web app with MySQL replication
 
Load balancing
Load balancingLoad balancing
Load balancing
 
Meetup TestingAR 2016 - Performance testing durante y después
Meetup TestingAR 2016 - Performance testing durante y despuésMeetup TestingAR 2016 - Performance testing durante y después
Meetup TestingAR 2016 - Performance testing durante y después
 
Load testing with Telerik Test Studio
Load testing with Telerik Test StudioLoad testing with Telerik Test Studio
Load testing with Telerik Test Studio
 
QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...
QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...
QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...
 
Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule” Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule”
 
Load & Performance TESTING
Load & Performance TESTINGLoad & Performance TESTING
Load & Performance TESTING
 
CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...
CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...
CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...
 
HAProxy
HAProxy HAProxy
HAProxy
 
Tsung Intro presentation 2013
Tsung Intro presentation 2013Tsung Intro presentation 2013
Tsung Intro presentation 2013
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load Balancer
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open source
 
XenApp Load Balancing
XenApp Load BalancingXenApp Load Balancing
XenApp Load Balancing
 
A Gentoo Environment at Gaikai
A Gentoo Environment at GaikaiA Gentoo Environment at Gaikai
A Gentoo Environment at Gaikai
 
Lessons from Highly Scalable Architectures at Social Networking Sites
Lessons from Highly Scalable Architectures at Social Networking SitesLessons from Highly Scalable Architectures at Social Networking Sites
Lessons from Highly Scalable Architectures at Social Networking Sites
 
Class warshal2
Class warshal2Class warshal2
Class warshal2
 
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
 

Ähnlich wie Load Balancing with Apache

Apache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual HostingApache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual Hosting
webhostingguy
 
Load Impact
Load Impact Load Impact
Load Impact
z-999
 
Tips
TipsTips
Tips
mclee
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
Phil Windley
 

Ähnlich wie Load Balancing with Apache (20)

Apache - Quick reference guide
Apache - Quick reference guideApache - Quick reference guide
Apache - Quick reference guide
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
 
Apache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual HostingApache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual Hosting
 
Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
Webinar Slides: New Tungsten Dashboard - Overview, Installation and Architecture
Webinar Slides: New Tungsten Dashboard - Overview, Installation and ArchitectureWebinar Slides: New Tungsten Dashboard - Overview, Installation and Architecture
Webinar Slides: New Tungsten Dashboard - Overview, Installation and Architecture
 
Training Slides: Basics 106: Tungsten Dashboard Overview, Installation and Ar...
Training Slides: Basics 106: Tungsten Dashboard Overview, Installation and Ar...Training Slides: Basics 106: Tungsten Dashboard Overview, Installation and Ar...
Training Slides: Basics 106: Tungsten Dashboard Overview, Installation and Ar...
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Load Impact
Load Impact Load Impact
Load Impact
 
Server Side? Swift
Server Side? SwiftServer Side? Swift
Server Side? Swift
 
Tips
TipsTips
Tips
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
 
Using aphace-as-proxy-server
Using aphace-as-proxy-serverUsing aphace-as-proxy-server
Using aphace-as-proxy-server
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 

Mehr von Bradley Holt

Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012
Bradley Holt
 

Mehr von Bradley Holt (16)

Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Entity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf BostonEntity Relationships in a Document Database at CouchConf Boston
Entity Relationships in a Document Database at CouchConf Boston
 
CouchConf NYC CouchApps
CouchConf NYC CouchAppsCouchConf NYC CouchApps
CouchConf NYC CouchApps
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
ZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDBZendCon 2011 Learning CouchDB
ZendCon 2011 Learning CouchDB
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
CouchDB at New York PHP
CouchDB at New York PHPCouchDB at New York PHP
CouchDB at New York PHP
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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...
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Load Balancing with Apache

  • 1. Load Balancing with Apache Bradley Holt (http://bradley-holt.com/) @BradleyHolt (http://twitter.com/BradleyHolt)
  • 5. Author http://oreilly.com/catalog/9781449303129/ http://oreilly.com/catalog/9781449303433/
  • 7. About Apache Open source Serves over 100 million websites Can run in many different modes, depending on your needs, via MultiProcessing Modules (MPMs) The Apache Software Foundation (ASF) supports many other open source software projects
  • 9. Software Load Balancers HAProxy Varnish Pound Perlbal Squid nginx Linux-HA (High-Availability Linux) on Linux Standard Base (LSB)
  • 10. Hosted Load Balancers Amazon’s Elastic Load Balancing Rackspace Cloud Load Balancers
  • 12. Properties of a SN System Each node operates independently No single point of contention PHP is shared nothing by default…
  • 13. Breaking SN Sessions require sharing (or require the use of sticky sessions) Databases are the most common single point of contention (this is why eventual consistency is important) Storing variables in memory between requests breaks SN (possible in Java and .NET)
  • 14. Practical SN Techniques Store sessions in a memcached cluster—this makes web nodes SN For database applications: • send writes to a write-only master • replicate to multiple read-only nodes • read-only nodes are now effectively SN Clustering/partitioning/sharding can help, too (but painful). Alternatively, use a “NoSQL” database (e.g. CouchDB is SN).
  • 16. Required Modules mod_proxy mod_proxy_http (assuming you’re load balancing HTTP requests) mod_proxy_balancer mod_headers (for sticky sessions) mod_rewrite (for advanced con gurations)
  • 18. # Create a load balancer named "web-nodes" <Proxy balancer://web-nodes> # Add three load balancer members BalancerMember http://www1.example.com BalancerMember http://www2.example.com BalancerMember http://www3.example.com </Proxy> # Send all requests to the "web-nodes" balancer ProxyPass / balancer://web-nodes
  • 19. Apache allows traffic to be balanced by number of requests (lbmethod=byrequests), bytes transferred (lbmethod=bytraffic), or by the number of currently pending requests (lbmethod=bybusyness).
  • 20. Sticky Sessions in PHP (your mileage may vary)
  • 21. # Create a load balancer named "web-nodes" <Proxy balancer://web-nodes> # Add three load balancer members BalancerMember http://www1.example.com BalancerMember http://www2.example.com BalancerMember http://www3.example.com # Use the PHPSESSID for sticky sessions ProxySet stickysession=PHPSESSID </Proxy> # Send all requests to the "web-nodes" balancer ProxyPass / balancer://web-nodes
  • 22. Create Your Own Sticky Sessions
  • 23. # Set a cookie Header add Set-Cookie "NODE=%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED # Create a load balancer named "web-nodes" <Proxy balancer://web-nodes> # Add three load balancer members BalancerMember http://www1.example.com route=1 BalancerMember http://www2.example.com route=2 BalancerMember http://www3.example.com route=3 # Use the NODE cookie for sticky sessions ProxySet stickysession=NODE </Proxy> # Send all requests to the "web-nodes" balancer ProxyPass / balancer://web-nodes
  • 24. Use a private network to connect your load balancer to your balancer members. This allows for dedicated bandwidth and opens up the possibility of offloading SSL handling to the load balancer.
  • 25. Route Based on HTTP Method
  • 26. # Enable mod_rewrite RewriteEngine On # Send POST, PUT, and DELETEs to "write" balancer RewriteCond %{REQUEST_METHOD} ^(POST|PUT|DELETE)$ RewriteRule ^/(.*)$ balancer://write$1 [P] # Send GET, HEAD, and OPTIONS to "read" balancer RewriteCond %{REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$ RewriteRule ^/(.*)$ balancer://read$1 [P] # Modify HTTP response headers (e.g. Location) ProxyPassReverse / balancer://write ProxyPassReverse / balancer://read
  • 27. Consider con guring multiple load balancers, removing the load balancer as a single point of failure. This typically involves having two or more load balancers sharing the same IP address, with one con gured as a failover.
  • 29. Tsung Distributes load testing across multiple testing clients Can generate huge numbers of concurrent users Monitors CPU, memory, load, and network traffic Simulates dynamic sessions, as described in a con guration le Randomizes traffic patterns based on de ned probabilities Recording and playback of sessions HTML reports and graphs
  • 31. <?xml version="1.0"?> <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd"> <tsung loglevel="notice" version="1.0"> <!-- … --> </tsung>
  • 33. <!-- Client side setup --> <clients> <client host="test-a" weight="1" maxusers="10000" cpu="4" /> <client host="test-b" weight="1" maxusers="10000" cpu="4" /> </clients>
  • 35. <!-- Server side setup --> <servers> <server host="www" port="80" type="tcp" /> </servers>
  • 37. <!-- Load setup --> <load> <arrivalphase phase="1" duration="5" unit="minute" > <users arrivalrate="200" unit="second" /> </arrivalphase> </load>
  • 39. <!-- Session setup --> <session name="default" probability="100" type="ts_http" > <thinktime value="1" random="true" /> <request> <http method="GET" url="/" /> </request> </session>
  • 41. Tsung allows for monitoring using Erlang, SNMP, or Munin
  • 42. <!-- Monitoring setup --> <monitoring> <monitor host="www" type="munin" /> <monitor host="www1" type="munin" /> <monitor host="www2" type="munin" /> <monitor host="www3" type="munin" /> </monitoring>
  • 44. From Scaling CouchDB by Bradley Holt (O’Reilly). Copyright 2011 Bradley Holt, 978-1-449-30343-3
  • 46. From Scaling CouchDB by Bradley Holt (O’Reilly). Copyright 2011 Bradley Holt, 978-1-449-30343-3
  • 48. Thank You Bradley Holt (http://bradley-holt.com/) @BradleyHolt (http://twitter.com/BradleyHolt) Copyright © 2011 Bradley Holt. All rights reserved.

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n