Load balancing?
Fredrik Kristiansen
fredrik at nettby.no
Thu Jan 17 19:28:27 CET 2008
Hi,
We have just built us a function in PHP to load balance the images between 4
varnish servers. This function will always assign the same image to a server
every time. It doesn't select a random server. So the cache is distributed
across our 4 servers.
// Get varnish server path
function get_varnish_path($path) {
return 'http://'.$GLOBALS['servers'][crc32($path) %
count($GLOBALS['servers'])].$path;
}
// Varnish servers
$servers[] = 'varnish1.site.com';
$servers[] = 'varnish2.site.com';
$servers[] = 'varnish3.site.com';
$servers[] = 'varnish4.site.com';
// Example
print get_varnish_path('/image1.jpg').' ';
print get_varnish_path('/image12.jpg').' ';
print get_varnish_path('/image54.jpg').' ';
print get_varnish_path('/image488.jpg').' ';
print get_varnish_path('/image1.jpg').' ';
// Result
http://varnish4.site.com/image1.jpg
http://varnish1.site.com/image12.jpg
http://varnish3.site.com/image54.jpg
http://varnish1.site.com/image488.jpg
http://varnish4.site.com/image1.jpg
Fredrik Kristiansen
Nettby.no
On 17/01/2008, Ivan Voras <ivoras at fer.hr> wrote:
>
> Hi,
>
> I remember there were discussions about possible HTTP load balancing
> features in Varnish, but I don't know what was the result. Does Varnish
> support load balancing (even simple round-robin would be enough, IP
> address hashing would be better)?
>
> If not, does anyone has a recommendation about a nice and stable load
> balancer (ideally, it would also have an integrated HTTP accelerator to
> reduce the number of components to maintain in the system)?
>
>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-misc
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20080117/f375f059/attachment-0001.html>
More information about the varnish-misc
mailing list