SlideShare a Scribd company logo
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.

More Related Content

What's hot (20)

PPTX
How we solved Real-time User Segmentation using HBase
DataWorks Summit
 
PPTX
RESTful API - Best Practices
Tricode (part of Dept)
 
PDF
[124]네이버에서 사용되는 여러가지 Data Platform, 그리고 MongoDB
NAVER D2
 
PDF
좌충우돌 Data Engineering 학습기
DONGMIN LEE
 
PPTX
REST API
Tofazzal Ahmed
 
PDF
Power of the Log: LSM & Append Only Data Structures
confluent
 
PPTX
Physical architecture of sql server
Divya Sharma
 
PDF
Bringing API Management to AWS Powered Backends
Apigee | Google Cloud
 
PPS
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
PPTX
REST API 설계
Terry Cho
 
PPT
Oracle WebLogic Server Basic Concepts
James Bayer
 
PPTX
Avro introduction
Nanda8904648951
 
PPTX
Apache zookeeper 101
Quach Tung
 
PDF
03 - Hadoop. HDFS Shell-команды
Roman Brovko
 
PPTX
Nginx Testing in NAVER
형근 송
 
PDF
Cloudera Impala: A Modern SQL Engine for Apache Hadoop
Cloudera, Inc.
 
PPTX
Strategy of software design
Self-employed
 
PPTX
Intro to Big Data Hadoop
Apache Apex
 
PDF
Apache Hadoop and HBase
Cloudera, Inc.
 
PDF
Real-Time Market Data Analytics Using Kafka Streams
confluent
 
How we solved Real-time User Segmentation using HBase
DataWorks Summit
 
RESTful API - Best Practices
Tricode (part of Dept)
 
[124]네이버에서 사용되는 여러가지 Data Platform, 그리고 MongoDB
NAVER D2
 
좌충우돌 Data Engineering 학습기
DONGMIN LEE
 
REST API
Tofazzal Ahmed
 
Power of the Log: LSM & Append Only Data Structures
confluent
 
Physical architecture of sql server
Divya Sharma
 
Bringing API Management to AWS Powered Backends
Apigee | Google Cloud
 
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
REST API 설계
Terry Cho
 
Oracle WebLogic Server Basic Concepts
James Bayer
 
Avro introduction
Nanda8904648951
 
Apache zookeeper 101
Quach Tung
 
03 - Hadoop. HDFS Shell-команды
Roman Brovko
 
Nginx Testing in NAVER
형근 송
 
Cloudera Impala: A Modern SQL Engine for Apache Hadoop
Cloudera, Inc.
 
Strategy of software design
Self-employed
 
Intro to Big Data Hadoop
Apache Apex
 
Apache Hadoop and HBase
Cloudera, Inc.
 
Real-Time Market Data Analytics Using Kafka Streams
confluent
 

Viewers also liked (20)

DOC
Cấu hình network load balancing trên windows server 2008
laonap166
 
PDF
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Jim Jagielski
 
PPT
Scaling Your Web Application
Ketan Deshmukh
 
PDF
Scaling your web app with MySQL replication
Giuseppe Maxia
 
PPT
Load balancing
Ahmed Sherief El-Dakhakhny
 
PPTX
Meetup TestingAR 2016 - Performance testing durante y después
Federico Toledo
 
PPTX
Load testing with Telerik Test Studio
Telerik Test Studio
 
PPTX
QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...
Federico Toledo
 
PPTX
Freeing India of “Divide & Rule”
cvikash
 
PDF
Load & Performance TESTING
Guido Serra
 
PPTX
CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...
Federico Toledo
 
PPTX
HAProxy
Arindam Nayak
 
PDF
Tsung Intro presentation 2013
Steffen Larsen
 
PPT
Web Server Load Balancer
MobME Technical
 
ODP
HAProxy scale out using open source
Ingo Walz
 
PPT
XenApp Load Balancing
Denis Gundarev
 
PDF
A Gentoo Environment at Gaikai
Guido Serra
 
PDF
Lessons from Highly Scalable Architectures at Social Networking Sites
Patrick Senti
 
PPTX
Class warshal2
Debarati Das
 
PPTX
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Federico Toledo
 
Cấu hình network load balancing trên windows server 2008
laonap166
 
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Jim Jagielski
 
Scaling Your Web Application
Ketan Deshmukh
 
Scaling your web app with MySQL replication
Giuseppe Maxia
 
Meetup TestingAR 2016 - Performance testing durante y después
Federico Toledo
 
Load testing with Telerik Test Studio
Telerik Test Studio
 
QA&test 2016 (Bilbao) Pros and Cons of Doing Performance Testing Along with D...
Federico Toledo
 
Freeing India of “Divide & Rule”
cvikash
 
Load & Performance TESTING
Guido Serra
 
CMG imPACt2016 - Mobile performance testing - Vendor training - Federico Tole...
Federico Toledo
 
HAProxy
Arindam Nayak
 
Tsung Intro presentation 2013
Steffen Larsen
 
Web Server Load Balancer
MobME Technical
 
HAProxy scale out using open source
Ingo Walz
 
XenApp Load Balancing
Denis Gundarev
 
A Gentoo Environment at Gaikai
Guido Serra
 
Lessons from Highly Scalable Architectures at Social Networking Sites
Patrick Senti
 
Class warshal2
Debarati Das
 
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Federico Toledo
 
Ad

Similar to Load Balancing with Apache (20)

PDF
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
Jim Jagielski
 
PDF
Scalable Architecture 101
ConFoo
 
PDF
haproxy_Load_Balancer.pdf
crezzcrezz
 
PPTX
haproxy_Load_Balancer.pptx
crezzcrezz
 
KEY
Apache httpd-2.4 : Watch out cloud!
Jim Jagielski
 
PDF
zingmepracticeforbuildingscalablewebsitewithphp
hazzaz
 
PDF
Zingme practice for building scalable website with PHP
Võ Duy Tuấn
 
PDF
Zingme practice for building scalable website with PHP
Chau Thanh
 
PDF
01 zingme practice for building scalable website with php
Nguyen Duc Phu
 
PDF
Acus08 Advanced Load Balancing Apache2.2
Jim Jagielski
 
PDF
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Jim Jagielski
 
KEY
Apache httpd 2.4 Reverse Proxy
Jim Jagielski
 
PPTX
Apache Performance Tuning: Scaling Out
Sander Temme
 
PDF
Scale Apache with Nginx
Bud Siddhisena
 
KEY
How Flipkart scales PHP
Siddhartha Reddy Kothakapu
 
PDF
Apache httpd Reverse Proxy and Tomcat
Jim Jagielski
 
PDF
Server Load Balancer Test Methodology
Ixia
 
PDF
Load balancing at tuenti
Ricardo Bartolomé
 
PDF
Meetup #4: AWS ELB Deep dive & Best practices
AWS Vietnam Community
 
ODP
MNPHP Scalable Architecture 101 - Feb 3 2011
Mike Willbanks
 
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
Jim Jagielski
 
Scalable Architecture 101
ConFoo
 
haproxy_Load_Balancer.pdf
crezzcrezz
 
haproxy_Load_Balancer.pptx
crezzcrezz
 
Apache httpd-2.4 : Watch out cloud!
Jim Jagielski
 
zingmepracticeforbuildingscalablewebsitewithphp
hazzaz
 
Zingme practice for building scalable website with PHP
Võ Duy Tuấn
 
Zingme practice for building scalable website with PHP
Chau Thanh
 
01 zingme practice for building scalable website with php
Nguyen Duc Phu
 
Acus08 Advanced Load Balancing Apache2.2
Jim Jagielski
 
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Jim Jagielski
 
Apache httpd 2.4 Reverse Proxy
Jim Jagielski
 
Apache Performance Tuning: Scaling Out
Sander Temme
 
Scale Apache with Nginx
Bud Siddhisena
 
How Flipkart scales PHP
Siddhartha Reddy Kothakapu
 
Apache httpd Reverse Proxy and Tomcat
Jim Jagielski
 
Server Load Balancer Test Methodology
Ixia
 
Load balancing at tuenti
Ricardo Bartolomé
 
Meetup #4: AWS ELB Deep dive & Best practices
AWS Vietnam Community
 
MNPHP Scalable Architecture 101 - Feb 3 2011
Mike Willbanks
 
Ad

More from Bradley Holt (16)

PDF
Domain-Driven Design at ZendCon 2012
Bradley Holt
 
PDF
Domain-Driven Design
Bradley Holt
 
PDF
Entity Relationships in a Document Database at CouchConf Boston
Bradley Holt
 
KEY
CouchConf NYC CouchApps
Bradley Holt
 
KEY
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
KEY
ZendCon 2011 Learning CouchDB
Bradley Holt
 
KEY
jQuery Conference Boston 2011 CouchApps
Bradley Holt
 
KEY
OSCON 2011 CouchApps
Bradley Holt
 
KEY
OSCON 2011 Learning CouchDB
Bradley Holt
 
PDF
CouchDB at New York PHP
Bradley Holt
 
KEY
Intermediate PHP
Bradley Holt
 
PDF
New Features in PHP 5.3
Bradley Holt
 
PDF
Introduction to PHP
Bradley Holt
 
PDF
Resource-Oriented Web Services
Bradley Holt
 
PDF
Zend Framework Quick Start Walkthrough
Bradley Holt
 
ODP
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
 
Domain-Driven Design at ZendCon 2012
Bradley Holt
 
Domain-Driven Design
Bradley Holt
 
Entity Relationships in a Document Database at CouchConf Boston
Bradley Holt
 
CouchConf NYC CouchApps
Bradley Holt
 
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
ZendCon 2011 Learning CouchDB
Bradley Holt
 
jQuery Conference Boston 2011 CouchApps
Bradley Holt
 
OSCON 2011 CouchApps
Bradley Holt
 
OSCON 2011 Learning CouchDB
Bradley Holt
 
CouchDB at New York PHP
Bradley Holt
 
Intermediate PHP
Bradley Holt
 
New Features in PHP 5.3
Bradley Holt
 
Introduction to PHP
Bradley Holt
 
Resource-Oriented Web Services
Bradley Holt
 
Zend Framework Quick Start Walkthrough
Bradley Holt
 
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
 

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Designing Production-Ready AI Agents
Kunal Rai
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Biography of Daniel Podor.pdf
Daniel Podor
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
July Patch Tuesday
Ivanti
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

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.

Editor's Notes