Which is quicker? Memcache or file query? (using maxmind geoip.dat file)

Posted by tomcritchlow on Stack Overflow See other posts from Stack Overflow or by tomcritchlow
Published on 2010-12-31T11:22:19Z Indexed on 2010/12/31 16:54 UTC
Read the original article Hit count: 193

Hi, I'm using Python on Appengine and am looking up the geolocation of an IP address like this:

import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat')
Location = gi.country_code_by_addr(self.request.remote_addr)

(pygeoip can be found here: http://code.google.com/p/pygeoip/)

I want to geolocate each page of my app for a user so currently I lookup the IP address once then store it in memcache.

My question - which is quicker? Looking up the IP address each time from the .dat file or fetching it from memcache? Are there any other pros/cons I need to be aware of?

For general queries like this, is there a good guide to teach me how to optimise my code and run speed tests myself? I'm new to python and coding in general so apologies if this is a basic concept.

Thanks!

Tom

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine