[BangPypers] Country look up for an IP address

Chetan Nichkawde chetan.nichkawde at gmail.com
Thu Feb 19 15:12:53 CET 2009

I have recommended this for serving pages based on country exactly because of
MRU behavior. Typically, all your traffic for your site would be from one or
two country and those node would be sitting at top of the tree. If the users
of the site are uniformly distributed throughout the world then I would
recommend a simple binary search.


saju.pillai at gmail.com wrote:
> Chetan Nichkawde wrote:
>> Dear BangPypers,
>>    There was a problem posed to me to efficiently find the country for a 
>> given IP address. I have devised the solution for the same using splay 
>> tree. This could used in various places, like serving a web pages based 
>> on the country from which the request is coming from. The code can be 
>> downloaded from
> This is interesting.
> One point to note concerning the example use of "serving web pages based 
> on country". If your server load is generated from throughout the world, 
> you will waste time rotating the tree to provide MRU access. Splay trees 
> work best when you expect MRU behaviour, behaviour degrades if tree 
> nodes are accessed randomly - there is no benefit to moving recently 
> accessed nodes upwards to the root.
> That being said, there must be lots of MRU patterns in various apps 
> where this implementation can be used.
> srp
> -- 
> http://saju.net.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers

View this message in context: http://www.nabble.com/Country-look-up-for-an-IP-address-tp22097473p22101244.html
Sent from the BangPypers - Bangalore Python Users Group mailing list archive at Nabble.com.

More information about the BangPypers mailing list