GeoIP is excelent IP to location database provided from MaxMind.

The GeoIP databases have both free and paid versions. They also come in different versions - GeoIP to country, GeoIP to city and others.

The databases also come in several formats:

Surprisingly, the performance of SQL based GeoIP is often faster than binary file provided, but most people still prefer to use binary format, because keeping database up to date is easy.

The other problem of SQL based GeoIP solutions is that the database (MySQL), is the non scallable part of the website. So on busy websites, is much better to keep working with binary file instead to "bloating" the database. For best performance one can plase GeoIP data file on RAM-disk such /dev/shm.

So whats about NoSQL then?

Puting GeoIP in key value store is difficult task, because you need to check the IP against each range.

Luckaly for us, Redis offering sorted sets, where you can search by score.

So it is possible to build single sorted set and to put all IP ranges there. Because the values of the sorted set are unique, we need to add "uniqual" component to it - e.g. some sequential number.

The client must do zrangebyscore(), using numerical IP as score. Then we can store all data as the value, including unique copmonent.

For country based database we can store the two letter code there, without any significant memory usage - something like "US:1234", but we decided to store all data in external hash key ("US:1234": { code: US, name: USA }).
Doing it in this way it was possible later to import GeoIPCity, without any Redis schema changes.
This hash key also allow us to use same client code, without any modifications.

The memory usage on 64bit Redis was as following:

GeoIP Country without hashes 30 MB
GeoIP Country with hashes 35 MB
GeoIP City whit hashes 500 MB

Because programming code includes:

...we stored everything in Github repository here:

blog comments powered by Disqus

Articles library

Redis as session handler in PHP

How to use Redis for session handler in PHP in a way similar to msession or PostgreSQL sessions
Date: 2011-07

Tags: php system administration

Lazy starter script on Linux such Redhat CentOS or Fedora

How to quickly made Redis to start after Linux boot.
Date: 2011-07

Tags: system administration

Redis vs Memcached comparison

Here is basic comparison of Redis Memcached and Memcachedb.
Date: 2011-07

Tags: memcached

Why RDBMS and SQL are difficult...

...while sometimes NoSQL solution may be easier and way faster? This arcle deals with incremental counters and how they needs to be implemented properly in RDBMS-es such MySQL
Date: 2011-07
Updated: 2011-09-30

Tags: mysql programming anti-pattern

Seamless migration from one Redis server to another

How to use replication to migrate Redis server without service interruption
Date: 2011-07

Tags: system administration

Redis swap issue while save

Explanation why your server load average may spike and server to swap memory when running redis
Date: 2011-08-21

Tags: system administration

Amazon EC2 and Amazon ElastiCache service

Memcached at Amazon first impressions
Date: 2011-08-23

Tags: memcached cloud system administration

Understanding hash-max-zipmap-entries and 'hash of hashes' optimization

Explanation of config parameters such hash-max-zipmap-entries and how we can make huge memory savings in new Redis 2.2
Date: 2011-08-28

Tags: optimization php programming system administration

NoSQL database design example

This article explains how we made our article section
Date: 2011-09-02

Tags: mysql database design programming

Redis save and backup script

Simple backup script for Redis
Date: 2011-09-28

Tags: optimization system administration

Postgres 9.1 foreign data wrapper interface

Postgres 9.1 gives you ability to access data from different data sources including Redis
Date: 2011-10-20

Tags: memcached optimization mysql programming pgsql

Redis high traffic connection issue

Explanation on 'Cannot assign requested address' connection error
Date: 2011-11-12

Tags: optimization scaling system administration

Redis too many open files error on high traffic sites

Explanation on 'Accepting client connection: accept: Too many open files'
Date: 2011-12-21

Tags: memcached security system administration

PHP Redis bug with PHP 5.4

Description of bug PHP Redis bug
Date: 2012-07-02

Tags: php system administration

Case Study: Using Redis intersect on very large sets

Intersection of 2 x 120M MySQL records
Date: 2012-08-29

Tags: optimization cloud php mysql programming

Getting started with Python and Redis on CentOS 6.X

How to install and test Redis client for Python on CentOS
Date: 2013-03-21

Tags: python system administration

GeoIP in Redis

Put Maxmind's GeoIP in Redis for best berformance for cient apps written in PHP or Python
Date: 2013-03-24

Tags: optimization php scaling mysql programming python

Redis database file examination

Examination of Redis rdb file in order to find huge memory consumption
Date: 2013-08-23

Tags: optimization system administration

© Jul.2011 - 2019,
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy.