【问题标题】:Java and GeoLite database: How to use GeoLiteCity.dat in a production way?Java 和 GeoLite 数据库:如何以生产方式使用 GeoLiteCity.dat?
【发布时间】:2014-06-16 22:07:42
【问题描述】:

我下载了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)?

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

感谢和问候!

【问题讨论】:

    标签: java geolocation geoip maxmind


    【解决方案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 每周文件发布,也会有额外的清理/加载/索引数据库的开销。

    【讨论】:

    猜你喜欢
    • 2021-10-08
    • 2018-08-11
    • 2012-08-23
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2010-09-17
    相关资源
    最近更新 更多