Prev: Next: , Up: Top[Contents][Index]


6 Request balancing

When several backends are defined in a service, incoming requests will be distributed among them. This process is called balancing. By default, requests are distributed equally. This can be changed by assigning them a priority – a decimal number which controls a relative weight of the given backend in the distribution algorithm. The bigger the priority is, the more requests this backend gets from the total flow.

The distribution algorithm is defined by balancing strategy. As of version 4.14, pound supports two strategies: weighted random balancing and interleaved weighted round robin balancing.

Weighted Random Balancing

This is the default strategy. Each backend is assigned a numeric priority between 0 and 9, inclusive. The backend to use for each request is determined at random taking into account backend priorities, so that backends with numerically greater priorities have proportionally greater chances of being selected than the ones with lesser priorities.

The share of requests a backend receives can be estimated as:

Pi / S(P)

where Pi is the priority of the backend with index i, and S(P) is the sum of all priorities.

Interleaved Weighted Round Robin Balancing

Requests are assigned to each backend in turn. Backend priorities, or weights, are used to control the share of requests received by each backend. The greater the weight, the more requests will be sent to this backend. In general, the share of requests assigned to a backend is calculated by the following relation:

(Pi + 1) / (N + S(P))

where N is total number of backends, and Pi and S(P) are as discussed above.

Weighted random balancing is used by default. Each backend gets the default priority 5, unless another value is expressly assigned using the Priority statement, e.g.:

Service
    Backend
        Address 192.168.0.1
        Port 80
        Priority 1
    End
    Backend
        Address 192.168.0.2
        Port 80
        Priority 9
    End
End

In this example, backend 192.168.0.2 will receive roughly 9 times more requests than backend 192.168.0.1.

The balancing strategy to use is defined by the Balancer keyword, which can appear either in the global scope or within a Service section. Its argument can be one of:

random

Use weighted random balancing (default).

iwrr

Use interleaved weighted round robin balancing.

The Balancer statement appearing in the global scope defines balancing strategy for all services that don’t have Balancer statement on their own.


Prev: Next: , Up: Top[Contents][Index]