Java和GeoLite数据库:如何以生产方式使用GeoLiteCity.dat?

时间:2014-06-16 22:07:43

标签: java geolocation geoip maxmind

我下载了GeoLite City数据库,我可以使用Java访问数据库,以便通过以下方式获取IP地址的相应位置信息:

File file = new File("C:\\GeoLiteCity.dat");
LookupService lookup = new LookupService(file, LookupService.GEOIP_MEMORY_CACHE);
Location location = lookup.getLocation("123.123.12.34");

我的问题:在生产环境中,以上述方式打开每个IP地址的文件显然是不可取的。如何以生产方式使用此数据库(假设使用GeoLiteCity.dat)?

非常感谢任何输入或指针。

谢谢和问候!

1 个答案:

答案 0 :(得分:1)

两个建议:

1. Make the LookupService static (lookup) and available in the memory (Singleton)
2. Load this file (or CSV file version) into a database (New tables, columns etc...)

我不确定数据库是否能够大大提高性能,而不仅仅是将服务加载到内存中并进行搜索。使用这些GeoLite每周文件发布,还会有额外的清理/加载/索引数据库的开销。

相关问题