Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MaxMind: loading GeoIP2 mmdb into memory for fast read

Tags:

maxmind

I am using MaxMind's GeoIP2 to get the geo information for an IP address. In my Java web application, the

DatabaseReader reader = new DatabaseReader.Builder(new File("C:\GeoLite2-City.mmdb").withCache(new CHMCache()).build();

I am hoping to load the entire file into memory for efficient/fast read.

Is the way shown above the most efficient/fast way of using the mmdb database?

like image 233
curious1 Avatar asked Dec 08 '25 16:12

curious1


1 Answers

The code you pasted will memory-map the file and use the data cache. It should be efficient, but it will not load the whole database into memory. If you want to do that, you would need to load the database using the fileMode builder option, e.g.:

DatabaseReader reader = new DatabaseReader
    .Builder(new File("C:\GeoLite2-City.mmdb")
    .fileMode(com.maxmind.db.Reader.FileMode.MEMORY)
    .withCache(new CHMCache())
    .build();

However, in most cases, you will probably not see a performance difference between this and the memory-mapped file.

like image 144
Greg Oschwald Avatar answered Dec 12 '25 09:12

Greg Oschwald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!