Balancer Algorithms

Hello,

I want to distribute traffic across backend servers based purely on
availability.

I don’t want to send some traffic to one which is less busy, or has
less traffic, , or has fewer connections, I want to send traffic to a
second node only if the first node is unavailable.

How can I do this?

S.

On Thu, Nov 20, 2008 at 11:09:08AM +0000, Stephen Nelson-Smith wrote:

Hello,

I want to distribute traffic across backend servers based purely on
availability.

I don’t want to send some traffic to one which is less busy, or has
less traffic, , or has fewer connections, I want to send traffic to a
second node only if the first node is unavailable.

How can I do this?

see http://wiki.codemongers.com/NginxHttpUpstreamModule , you are
looking for
the “backup” argument.

Stephen Nelson-Smith schrieb:

S.

take a look at http://wiki.codemongers.com/NginxHttpUpstreamModule

the section “server” describes some options, e.g.

–snip–

backup - (0.6.7 or later) only uses this server if the non-backup
servers are all down or busy

–snap–

so this should work:

upstream backend {
server backend1.example.com;
server backend2.example.com backup;
}

kind regards

Philipp

*** ACHTUNG: Meine Telefonnummer hat sich geändert: 203 - 4669 ***

Dipl.-Inf. Philipp Michels
Rechenzentrum Universitaet Freiburg
Stefan-Meier-Str. 31a, 79104 Freiburg
Tel: 0761/203-4669, Fax: 0761/203-4643
E-Mail: [email protected]

PGP-Key: http://omnibus.ruf.uni-freiburg.de/~michels/pubkey.asc
PGP-Fingerprint: 4212 96E7 351E C00D 5506 5B59 EEEE CA1A 9D25 137E

On Thu, Nov 20, 2008 at 12:08:05PM +0000, Stephen Nelson-Smith wrote:

Hi,

so this should work:

upstream backend {
server backend1.example.com;
server backend2.example.com backup;
}

That looks good. If I add backend3.example.com backup, I assume that
is used only if backed2 fails.

No, not really (AFAIK). There are two sets of backends: normal and
backup ones. When all normal backends fail, Nginx switches to the backup
set and vice versa.

Oh, and backup backends probably don’t work at all with upstream_fair
(never tested, left as a TODO in source).

Best regards,
Grzegorz N.

Hello!

On Thu, Nov 20, 2008 at 12:08:05PM +0000, Stephen Nelson-Smith wrote:

Hi,

so this should work:

upstream backend {
server backend1.example.com;
server backend2.example.com backup;
}

That looks good. If I add backend3.example.com backup, I assume that
is used only if backed2 fails.

No, your assumption is wrong. All servers with backup flag are
activated if all servers without backup flag are dead.

Maxim D.

Hi,

That looks good. If I add backend3.example.com backup, I assume that
is used only if backed2 fails.

No, your assumption is wrong. All servers with backup flag are
activated if all servers without backup flag are dead.

Ahh… So is there a way to do this:

  • backend1 (primary)>
  • if backend1 fails, send traffic to backend2
  • if backend2 fails, send traffic to backend3

S.

Hi,

so this should work:

upstream backend {
server backend1.example.com;
server backend2.example.com backup;
}

That looks good. If I add backend3.example.com backup, I assume that
is used only if backed2 fails.

S.

Is this a good replacement instead of using Haproxy?

Asif A.

On Thu, 20 Nov, 2008 at 18:20:25 +0530, Asif A. wrote:

Is this a good replacement instead of using Haproxy?
I’m afraid not.
HAProxy is specially designed for TCP and HTTP-based applications. It
has more functionalities.
Anyway, it depends on your demands. Maybe we need some comparison
between the two in production environment.