Skip to content

Instantly share code, notes, and snippets.

perl_set $dice 'sub {
if (@pool) {
push @pool, shift @pool;
} else {
@pool = ("/test1", "/test2");
}
my $r = shift;
my $root = $r->variable("document_root");
my $uri = $r->uri;
@zzzcpan
zzzcpan / sharded-balancing-nginx.txt
Created March 19, 2012 19:01
Sharded load balancing with nginx and perl
# Balancing over 4 nodes by hashing URI (consistently with md5)
# onto 16 shards.
upstream x0 { server 192.168.0.2; server 192.168.0.3 backup; }
upstream x1 { server 192.168.0.2; server 192.168.0.4 backup; }
upstream x2 { server 192.168.0.2; server 192.168.0.5 backup; }
upstream x3 { server 192.168.0.2; server 192.168.0.3 backup; }
upstream x4 { server 192.168.0.3; server 192.168.0.4 backup; }