[squid-users] Fwd: Centralized Squid - design and implementation

Kinkie gkinkie at gmail.com
Sun Nov 16 17:27:44 UTC 2014


Forwarding, as it may be useful to others.


---------- Forwarded message ----------
From: Kinkie <gkinkie at gmail.com>
Date: Sun, Nov 16, 2014 at 6:27 PM
Subject: Re: [squid-users] Centralized Squid - design and implementation
To: alberto <alberto.furia at gmail.com>


On Sun, Nov 16, 2014 at 5:53 PM, alberto <alberto.furia at gmail.com> wrote:
> Hi Kinkie
>
> On Sun, Nov 16, 2014 at 5:22 PM, Kinkie <gkinkie at gmail.com> wrote:
>>
>>    if (dest_hash)
>>      return "PROXY local_proxy1:port; PROXY local_proxy2:port; DIRECT";
>>    return "PROXY local_proxy2:port; PROXY local_proxy1:port; DIRECT"
>> }
>> This will balance by the final digit of the destination IP of the
>> service.
>
>
> With this configuration i can only balance between two nodes in normal
> situation right?
> Whati if i would like to have more nodes balancing the traffic? In case of
> very high load for example.

The hashing is a bit simplicistic. You could do something like (again:
untested):

// if the code works, this is the only tuneable needed. Everything
else self-adjusts
var proxies = ["PROXY proxy1:port1", "PROXY proxy2:port2", "PROXY
proxy3.port3"];

function hash(host, buckets) { // returns a host-dependent integer
between 0 and buckets
  var hostip = dnsResolve(host);
  if (!hostip) // dns resolution failure
    return 0;
  return hostip.slice(hostip.lastIndexOf(".")) % buckets;
}

function FindProxyForURL(url, host) {
  var h = hash(host, proxies.length+1);
  var p = proxies;
  for (var j = 0; j < h; ++j)
    p.unshift(p.pop()); // rotate the "p" array
  return p.join("; ") + "; DIRECT";
}



--
    Francesco


-- 
    Francesco


More information about the squid-users mailing list