ip2region-IP到地名(國(guó)家區(qū)域省份城市縣地址)映射查詢庫(kù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
ip2region—— 準(zhǔn)確率 99.9% 的 ip 地址定位庫(kù),0.0x 毫秒級(jí)查詢,數(shù)據(jù)庫(kù)文件大小只有 1.5M,提供了 java、php、c、python、node.js、golang 查詢綁定和 Binary、B 樹(shù)、內(nèi)存三種查詢算法,媽媽再也不用擔(dān)心我的 ip 地址定位! 1. 99.9% 準(zhǔn)確率,定時(shí)更新: 數(shù)據(jù)聚合了一些知名 ip 到地名查詢提供商的數(shù)據(jù),這些是他們官方的的準(zhǔn)確率,經(jīng)測(cè)試著實(shí)比純真啥的準(zhǔn)確多了。 每次聚合一下數(shù)據(jù)需要 1-2 天,會(huì)不定時(shí)更新。 2. 標(biāo)準(zhǔn)化的數(shù)據(jù)格式: 每條 ip 數(shù)據(jù)段都固定了格式:城市 Id | 國(guó)家 | 區(qū)域 | 省份 | 城市 | ISP 只有中國(guó)的數(shù)據(jù)精確到了城市,其他國(guó)家只能定位到國(guó)家,后前的選項(xiàng)全部是 0,已經(jīng)包含了全部你能查到的大大小小的國(guó)家。 (請(qǐng)忽略前面的城市 Id,個(gè)人項(xiàng)目需求) 3. 體積?。?/span> 生成的數(shù)據(jù)庫(kù)文件 ip2region.db 只有 1.5M (1.2 版本前 3.5M) 4. 多查詢客戶端的支持,0.0x 毫秒級(jí)別的查詢 已經(jīng)集成的客戶端有:java, php, c,python,php 擴(kuò)展,nodejs,golang。 提供了兩種查詢算法,響應(yīng)時(shí)間如下: 客戶端/binary算法/b-tree算法/Memory算法: java/0.x毫秒/0.x毫秒/0.1x毫秒 (使用RandomAccessFile) php/0.x毫秒/0.1x毫秒/0.1x毫秒 (php擴(kuò)展將有更快的速度)c/0.0x毫秒/0.0x毫秒/0.00x毫秒(b-tree算法基本穩(wěn)定在0.02x毫秒級(jí)別) python/0.x毫秒/0.1x毫秒/0.1x毫秒 任何客戶端 b-tree 都比 binary 算法快 5. 測(cè)試程序: java: cd binding/java ant all java -jar ip2region-{version}.jar ./data/ip2region.db php: php binding/php/testSearch ./data/ip2region.db c: cd binding/c/ gcc -g -O2 testSearch.c ip2region.c ./a.out ../../data/ip2region.db 均會(huì)看到如下界面: initializing B-tree ... +----------------------------------+ | ip2region test script | | Author: chenxin619315@gmail.com | | Type 'quit' to exit program | +----------------------------------+ ip2region>> 輸入 ip 地址開(kāi)始測(cè)試,第一次會(huì)稍微有點(diǎn)慢,在運(yùn)行命令后面接入 binary,memory 來(lái)嘗試對(duì)應(yīng)算法,建議使用 b-tree 算法,有速度和并發(fā)追求的使用 memory 算法。具體集成請(qǐng)參考不同客戶端的測(cè)試源碼。 C#使用方法: IP2Region.NetIP2Region c# xdb client InstallationInstall the package with NuGet Install-Package IP2Region.Net Usageusing IP2Region.Net.XDB;
//use default db and cache whole xdb file Searcher searcher = new Searcher(); searcher.Search("ipaddress value");
/* * custom cache policy and xdb file path * CachePolicy.Content default cache policy , cache whole xdb file , thread safe * CachePolicy.VectorIndex cache vector index , reduce the number of IO operations , not thread safe! * CachePolicy.File no cache , not thread safe! */ Searcher searcher = new Searcher(CachePolicy.File, "your xdb file path"); ASP.NET Core Usageservices.AddSingleton<ISearcher,Searcher>(); PerformanceBenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.856/21H2) AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx, 1 CPU, 8 logical and 4 physical cores .NET SDK=6.0.400 [Host] : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2 DefaultJob : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2
ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate. 該文章在 2023/7/3 14:38:04 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |