Slide 1

The mod_proxy_balancer
A module overview with practical
solutions to common problems
Daniel Ruggeri
• About Daniel Ruggeri
– DRuggeri <at>
• Standard Disclaimer
– I'm speaking personally and not on
behalf of my employer. The examples
and comments are my personal opinions
and should not be considered the official
practices or positions of MasterCard.
• Title is a misnomer
– Not just mod_proxy
– Application dependencies
• Warning – eye charts ahead!
– Examples may be hard to read
– Included for completeness
• Download this presentation!
Features of Load Balancers
Load balancing
Session stickiness
Connection pooling
Health checking
Dynamic modification of members
Cache/compress/shape traffic
TCP and SSL offload
Attack mitigation
Se d B
s a
Co sion lanc
Fa ne Stic ng
i c k
He love tion ine
r P o ss
Dy alth
na ch olin
Ca m ec
ch ic k
TC e/ M
P C o
At /SS om difi
ta L O pr ca
ck f es tio
M flo s/S n
iti ad h
How HTTPD Stacks Up
Hardware Layer 4
HTTP Appliance
Apache HTTPD
3 2 3 2 2 1 1 1 1
3 2 3 3 2 2 2 3 2
3 3 3 2 1 2 3 3 2
Load Distribution
• byrequests
– Perform balancing based solely on
requests served.
• bytraffic
– Perform balancing by byte count (in
response body) served.
• bybusyness
– Perform balancing based on how many
pending requests exist for a backend.
Load Distribution
• Asymmetric distribution
– loadfactor option for BalancerMember
• higher number == higher load.
– +H option for hot-standby
• Disables worker until others are unavailable.
• Don’t forget lbset.
– Selective proxying using ! and ordering
• Do not proxy certain requests or choose a
different backend.
Example: weighting
<Proxy balancer://mycluster>
BalancerMember loadfactor=2
BalancerMember smax=10 loadfactor=2
#Less powerful server, don't send as many requests there
BalancerMember smax=1 loadfactor=1
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID
Example: hot standby
<Proxy balancer://hotcluster>
#Hot standby
BalancerMember status=+H
ProxySet lbmethod=bytraffic
ProxyPass / balancer://hotcluster/
Example: selective proxying
<Proxy balancer://AppCluster1>
<Proxy balancer://AppCluster1>
ProxyPass /static/ !
ProxyPass /applicationA/ balancer://AppCluster1/
ProxyPass /applicationB/ balancer://AppCluster2/
ProxyPass / balancer://hotcluster/
Session Stickiness
• Built-in (as designed)
– mod_proxy_balancer includes facilities
to do this.
– Not always compatible or easy.
• Roll your own
– Use the built-in functions but tweak to
your liking.
• Route parameter comes into play
A Sticky Matter
• Many different formats for session
identifiers based on backend.
– Cookies, URLs, formats, etc
• Built-in is not 100% compatible.
– Requires dot or semicolon as a delimiter
Example: universal sticky
LoadModule headers_module modules/
<Proxy balancer://DanielCluster>
BalancerMember route=mercury
BalancerMember route=venus
ProxySet stickysession=DanielsApp_STICKY
Header add Set-Cookie
ProxyPass /daniel/ balancer://DanielCluster/daniel/
Connection Pooling
• Parameters
– min hard minimum
– max hard maximum
– smax soft maximum
– ttl time allowed above smax
• Other parameters come into play
• Complications…
Example: connection pooling
<Proxy balancer://myCluster>
BalancerMember min=5 smax=7 max=10
BalancerMember min=5 smax=7 max=10
ProxyPass / balancer://myCluster/
Failover/Health Check
• Yes, it does… but….
– Failover capability for connection only
• Connection errors fail over to next backend
• SSL errors go back to user (are not taken
out of service).
• Hung backend errors go back to user (are
not taken out of service).
– 2.2.17 has some light intelligence added
Failover/Health Check
• No heath check capability
– Requires real, live traffic
– In the future…
• Lots of discussion on [email protected] list
– Something in 2.4?
• You must come up with a way to work
around it
Failover - Mitigating Controls
• connectiontimeout
– Sets the number of seconds to wait for a
TCP connection.
• ProxyTimeout
– Sticks and stones – fail fast (but not a
real failure).
• Monitoring
– Create external monitoring to force traffic
through HTTPD.
Dynamic Modification
• BalancerManager is currently the only
method to modify members.
• Limited set of parameters
– Balancer
• sticky identifier, timeout, failover, lbmethod
– Worker
• loadfactor, lbset, route, redirect
• Be safe out there
• Caching via mod_cache
– Too much to cover here.
• Compress via mod_deflate
• Shape via…
– mod_headers, mod_rewrite,
mod_substitute, mod_env/mod_setenvif,
mod_expires, mod_*filter
• The sky is the limit!
Example: traffic shaping
ProxyPass /app balancer://myCluster/appl
ProxyPassReverse /app balancer://myCluster/app
<Location /app>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s||http://mypage|n"
RequestHeader set environment production
AddOutputFilterByType DEFLATE text/html text/xml
TCP/SSL offload
• Funnel into the pipeline
– Many requests <-> one backend
– keepalive is a beautiful thing
• SSL benefits as well
– Can run HTTP or HTTPS to backend
• Either will be more efficient!
Attack Mitigation
• Security modules
• Separation
– Tiered approach
– Standards enforcement
• Filtering/Blocking/Restricting
– Allow from certain hosts
– Authn/Authz modules

similar documents