Skip to content

chetan/fast_maxmind_geoip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Faster MaxMind GeoIP

While the MaxMind GeoIP library is thread-safe, it achieves thread-safety by adding the synchronized keyword to various methods. This obviously slows things down quite dramatically in a heavily threaded environment (e.g., when used in a web service) due to thread contention on these methods.

This fork solves those issues, with a few caveats:

  • Only the IPv4 getCountry() APIs have been modified
  • IPv6 is supported via getCountryCode(), but uses the same old code paths
  • Optimized for in-memory cache use only
  • Database reloading has been disabled (extra method call/stat on every hit)
  • Netmask calculation has been disabled

Modifications

The following modifications were made to the original LookupService class:

  • Implemented a faster ipToLong(string) method which uses no intermediate objects (i.e. InetAddress)
  • Removed synchronized keywords on seekCountry() and _check_mtime() methods
  • Modified seekCountry() - skip mtime check, ignore netmask, only use in-memory cache
  • Added getCountryCode() method
  • _check_mtime() is now a no-op; as such, updating the db during operation is not currently supported

Usage

FastLookupService geo = new FastLookupService("/path/to/db", FastLookupService.GEOIP_MEMORY_CACHE);
String countryCode = geo.getCountryCode("4.2.2.2");

About

A highly optimized version of the MaxMind GeoIP Library for Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages