.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Perlbal::Manual::LoadBalancer 3pm" .TH Perlbal::Manual::LoadBalancer 3pm "2022-06-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Perlbal::Manual::LoadBalancer \- Using Perlbal as a Load Balancer .SS "\s-1VERSION\s0" .IX Subsection "VERSION" Perlbal 1.78. .SS "\s-1DESCRIPTION\s0" .IX Subsection "DESCRIPTION" How to configure a Perlbal Load Balancing service. .SS "\s-1READ ME FIRST\s0" .IX Subsection "READ ME FIRST" Please read Perlbal::Manual::Configuration first for a better explanation on how to configure Perlbal. This document will make much more sense after reading that. .SS "Using Perlbal as a Load Balancer" .IX Subsection "Using Perlbal as a Load Balancer" For a better understanding of how to set up Perbal as a Load Balancer, it should be noted that a Load Balancer and a Reverse Proxy can often be the same thing; not always, but often. .PP A Load Balancer is a server (or device) that balances requests across a number of servers to spread the load. A Reverse Proxy can still do this but also have a number of other features. .PP Perlbal as a Reverse Proxy provides features such as buffering content, preserving connections to the backend servers, starting connections ahead of time and a high priority queue, among others. .PP You could almost say that a Load Balancer is a subset of a Reverse Proxy (it's not, but you could). .PP When it comes to Perlbal, the Load Balancer is implemented as a Reverse Proxy without all the extra options, and that's why you set the role of a Load Balancer to \f(CW\*(C`reverse_proxy\*(C'\fR: .PP .Vb 1 \& SET role = reverse_proxy .Ve .PP \fISimple load balancing\fR .IX Subsection "Simple load balancing" .PP Let's assume you want to configure two machines to serve your website and you want to let Perlbal decide how to balance the requests. For the sake of this exercise let's assume you have two servers at: .PP .Vb 2 \& 10.0.0.1:80 \& 10.0.0.2:80 .Ve .PP And now you want to use these two machines to serve your website at: .PP .Vb 1 \& 10.0.0.3:80 .Ve .PP Here's a sample configuration to make this happen: .PP .Vb 3 \& CREATE POOL mywebsite \& POOL mywebsite ADD 10.0.0.1:80 \& POOL mywebsite ADD 10.0.0.2:80 \& \& CREATE SERVICE service_mywebsite \& SET role = reverse_proxy \& SET pool = mywebsite \& SET listen = 10.0.0.3:80 \& ENABLE service_mywebsite .Ve .PP The first line defines a pool of machines called \f(CW\*(C`mywebsite\*(C'\fR. The second and third lines add your two machines to that pool (note that the indentation is not mandatory). .PP After that you define a service called \f(CW\*(C`service_mywebsite\*(C'\fR with the role \f(CW\*(C`reverse_proxy\*(C'\fR set to listen on \f(CW\*(C`10.0.0.3:80\*(C'\fR and using the pool \f(CW\*(C`mywebsite\*(C'\fR to serve the requests. .PP The last line is what allows you have several services configured in a file even if they are not currently active (a common scenario is to configure everything on the file and then enable/disable services on-the-fly as required; see Perlbal::Manual::Management for more information on this process). .PP \fIThe Load Balancing algorithm\fR .IX Subsection "The Load Balancing algorithm" .PP Perlbal uses a highly efficient load balancing algorithm. It is very effective for distributing dynamic web requests among potentially heterogeneous hardware. .PP First, backend servers must have their MaxClients (for apache, or equivalent) setting tuned to a reasonable limit. If your hardware can run 20 requests in parallel before running out of \s-1CPU,\s0 set MaxClients to 20. .PP Next, by default Perlbal will distribute requests randomly. Opening a new connection to any available backend, and issuing the request. .PP The proper algorithm is able to be used if \f(CW\*(C`verify_backend\*(C'\fR, \f(CW\*(C`backend_persist\*(C'\fR, \f(CW\*(C`backend_persist_cache\*(C'\fR, and \f(CW\*(C`connect_ahead\*(C'\fR are enabled. .PP .Vb 4 \& SET persist_backend = on \& SET verify_backend = on \& SET backend_persist_cache = 5 \& SET connect_ahead = 2 .Ve .PP In this configuration, Perlbal will only route client requests to backends that it knows are real processes, instead of the \s-1OS\s0 listen queue. It will attempt to reuse pre-verified backends, and will attempt to create slightly more idle connections than it needs in preparation of future requests. .PP When you put all this together, it becomes less likely that a client will wait for Perlbal to find an available backend. By setting your MaxClients properly, backends are able to serve traffic without getting overwhelmed. If no backends are available, Perlbal will queue them internally, rather than overload backends. .PP You would want to disable \f(CW\*(C`verify_backend\*(C'\fR if you are balancing across image servers, or other extremely lightweight requests. .SS "\s-1SEE ALSO\s0" .IX Subsection "SEE ALSO" Perlbal::Manual::Configuration, Perlbal::Manual::FailOver, Perlbal::Manual::Management, Perlbal::Manual::ReverseProxy.