MaxMind:将 GeoIP2 mmdb 加载到内存中以进行快速读取
MaxMind: loading GeoIP2 mmdb into memory for fast read
我正在使用 MaxMind 的 GeoIP2 获取 IP 地址的地理信息。在我的 Java 网络应用程序中,
DatabaseReader reader = new DatabaseReader.Builder(new File("C:\GeoLite2-City.mmdb").withCache(new CHMCache()).build();
我希望将整个文件加载到内存中以供 efficient/fast 读取。
上面的方式是不是最efficient/fast使用mmdb数据库的方式?
您粘贴的代码将对文件进行内存映射并使用数据缓存。它应该是高效的,但它不会将整个数据库加载到内存中。如果你想这样做,你需要使用 fileMode
构建器选项加载数据库,例如:
DatabaseReader reader = new DatabaseReader
.Builder(new File("C:\GeoLite2-City.mmdb")
.fileMode(com.maxmind.db.Reader.FileMode.MEMORY)
.withCache(new CHMCache())
.build();
但是,在大多数情况下,您可能看不到此文件与内存映射文件之间的性能差异。
我正在使用 MaxMind 的 GeoIP2 获取 IP 地址的地理信息。在我的 Java 网络应用程序中,
DatabaseReader reader = new DatabaseReader.Builder(new File("C:\GeoLite2-City.mmdb").withCache(new CHMCache()).build();
我希望将整个文件加载到内存中以供 efficient/fast 读取。
上面的方式是不是最efficient/fast使用mmdb数据库的方式?
您粘贴的代码将对文件进行内存映射并使用数据缓存。它应该是高效的,但它不会将整个数据库加载到内存中。如果你想这样做,你需要使用 fileMode
构建器选项加载数据库,例如:
DatabaseReader reader = new DatabaseReader
.Builder(new File("C:\GeoLite2-City.mmdb")
.fileMode(com.maxmind.db.Reader.FileMode.MEMORY)
.withCache(new CHMCache())
.build();
但是,在大多数情况下,您可能看不到此文件与内存映射文件之间的性能差异。