# Network proximity calculation

**URL:** <https://www.ruby-forum.com/t/network-proximity-calculation/153791>\
**Category:** Ruby\
**Created:** [November 21, 2008, 5:04am UTC](https://www.ruby-forum.com/t/network-proximity-calculation/153791 "2008-11-21T05:04:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [November 21, 2008, 5:04am UTC](https://www.ruby-forum.com/t/network-proximity-calculation/153791/1 "2008-11-21T05:04:45Z")

</div>

Hello,

I’m trying to do a home grown load balancing solution that needs to  
determine which of the two data centers a visitor should be sent to.  
I’d like to do some type of a network proximity calculation that  
includes latency and number of hops which will allow me to redirect the  
user to their “closest/fastest” server.

I know all about CDNs and Appliance Load Balancers (F5); I’m looking for  
a custom software solution instead.

Any pointers is much appreciated.

GP.

---

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [November 21, 2008, 5:42am UTC](https://www.ruby-forum.com/t/network-proximity-calculation/153791/2 "2008-11-21T05:42:43Z")

</div>

On Thu, Nov 20, 2008 at 11:00 PM, Grayson P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to do a home grown load balancing solution that needs to  
> determine which of the two data centers a visitor should be sent to.  
> I’d like to do some type of a network proximity calculation that  
> includes latency and number of hops which will allow me to redirect the  
> user to their “closest/fastest” server.
> 
> I know all about CDNs and Appliance Load Balancers (F5); I’m looking for  
> a custom software solution instead.
> 
> Any pointers is much appreciated.

traceroute -n -w 1 -q 1 $USER | awk ‘{sum += $3} END { printf  
(“%8.2f\n”,sum)}’  
😉

Depending on how much time you can burn up front, one option may be to  
query the user’s IP address via a geo-ip-location; perhaps cache the  
result based on either the user’s full IP address or class C subnet to  
reduce the external API calls. Maybe traceroute and/or ping from each  
data center and geo-locate, caching all the results?
