• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Load Balancing with Apache
 

Load Balancing with Apache

on

  • 39,396 views

This is a presentation made at the Burlington, Vermont PHP Users Group about configuring load balancing using the Apache HTTP Server. Load balancing is a technique that can distribute work across ...

This is a presentation made at the Burlington, Vermont PHP Users Group about configuring load balancing using the Apache HTTP Server. Load balancing is a technique that can distribute work across multiple server nodes—here we will discuss load balancing HTTP (i.e. web) traffic. There are many software and hardware load balancing options available including HAProxy, Varnish, Pound, Perlbal, Squid, nginx, and Linux-HA (High-Availability Linux) on Linux Standard Base (LSB). However, many web developers are already familiar with Apache as a web server and it is relatively easy to also configure Apache as a load balancer.

Related concepts such as shared nothing architecture are discussed. We also take a look at some basic load balancing scenarios and features including sticky sessions and proxying requests based on HTTP method. Distributed load testing with Tsung is briefly discussed as well.

Statistics

Views

Total Views
39,396
Views on SlideShare
33,620
Embed Views
5,776

Actions

Likes
37
Downloads
917
Comments
0

29 Embeds 5,776

http://bradley-holt.com 3073
http://css.dzone.com 2448
http://www.planet-php.net 81
http://hwcss.blogspot.com 44
https://unipac-uberlandia.blackboard.com 25
http://php.dzone.com 20
http://translate.googleusercontent.com 11
http://10.32.98.232 9
http://cloud.dzone.com 8
http://www.planet-php.org 8
http://planet-php.org 8
http://www.techgig.com 8
http://static.slidesharecdn.com 4
http://edu.liulizhi.info 3
http://www.techgig.timesjobs.com 3
http://www.lamptag.com 3
http://www.phpeye.com 3
http://swik.net 2
https://duckduckgo.com 2
http://webcache.googleusercontent.com 2
http://www.hanrss.com 2
http://www.netvibes.com 2
http://phpeye.com 1
http://planet-php.net 1
http://vokiel.tumblr.com 1
http://justborrowit.heroku.com 1
http://127.0.0.1:8795 1
https://www.google.at 1
http://a0.twimg.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Load Balancing with Apache Load Balancing with Apache Presentation Transcript

  • Load Balancing with Apache Bradley Holt (http://bradley-holt.com/)@BradleyHolt (http://twitter.com/BradleyHolt)
  • About Me
  • Co-Founder andTechnical Director
  • Contributor
  • Author http://oreilly.com/catalog/9781449303129/ http://oreilly.com/catalog/9781449303433/
  • Apache HTTP Server
  • About ApacheOpen sourceServes over 100 million websitesCan run in many different modes, depending on your needs,via MultiProcessing Modules (MPMs)The Apache Software Foundation (ASF) supports many otheropen source software projects
  • Alternatives
  • Software Load BalancersHAProxyVarnishPoundPerlbalSquidnginxLinux-HA (High-Availability Linux) on Linux Standard Base (LSB)
  • Hosted Load BalancersAmazon’s Elastic Load BalancingRackspace Cloud Load Balancers
  • Shared Nothing Architecture (SN)
  • Properties of a SN SystemEach node operates independentlyNo single point of contentionPHP is shared nothing by default…
  • Breaking SNSessions 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 TechniquesStore sessions in a memcached cluster—this makes web nodes SNFor database applications: • send writes to a write-only master • replicate to multiple read-only nodes • read-only nodes are now effectively SNClustering/partitioning/sharding can help, too (but painful).Alternatively, use a “NoSQL” database (e.g. CouchDB is SN).
  • Load Balancing Examples
  • Required Modulesmod_proxymod_proxy_http (assuming you’re load balancing HTTP requests)mod_proxy_balancermod_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" balancerProxyPass / balancer://web-nodes
  • Apache allows traffic to bebalanced by number of requests(lbmethod=byrequests), bytestransferred (lbmethod=bytraffic),or by the number of currently pendingrequests (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" balancerProxyPass / balancer://web-nodes
  • Create Your Own Sticky Sessions
  • # Set a cookieHeader 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" balancerProxyPass / balancer://web-nodes
  • Use a private network to connect yourload balancer to your balancermembers.This allows for dedicated bandwidthand opens up the possibility ofoffloading SSL handling to the loadbalancer.
  • Route Based on HTTP Method
  • # Enable mod_rewriteRewriteEngine On# Send POST, PUT, and DELETEs to "write" balancerRewriteCond %{REQUEST_METHOD} ^(POST|PUT|DELETE)$RewriteRule ^/(.*)$ balancer://write$1 [P]# Send GET, HEAD, and OPTIONS to "read" balancerRewriteCond %{REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$RewriteRule ^/(.*)$ balancer://read$1 [P]# Modify HTTP response headers (e.g. Location)ProxyPassReverse / balancer://writeProxyPassReverse / balancer://read
  • Consider con guring multiple loadbalancers, removing the load balanceras a single point of failure.This typically involves having two ormore load balancers sharing the sameIP address, with one con gured as afailover.
  • Distributed Load Testing with Tsung
  • TsungDistributes load testing across multiple testing clientsCan generate huge numbers of concurrent usersMonitors CPU, memory, load, and network trafficSimulates dynamic sessions, as described in a con guration leRandomizes traffic patterns based on de ned probabilitiesRecording and playback of sessionsHTML 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 monitoringusing 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.