update the command docs

This commit is contained in:
lion 2022-06-17 15:48:48 +08:00
parent 16720b7b26
commit db4aa26547
3 changed files with 22 additions and 21 deletions

View File

@ -1,4 +1,4 @@
# ip2region golang 查询客户端实现
# ip2region xdb golang 查询客户端实现
# 使用方式
@ -40,27 +40,27 @@ func main() {
# 编译测试程序
通过如下方式编译得到 searcher 可执行程序:
通过如下方式编译得到 xdb_searcher 可执行程序:
```bash
# 切换到 golang binding 根目录
go build -o searcher
go build -o xdb_searcher
```
# 查询测试
通过 `searcher search` 命令来测试 ip2region.xdb 的查询:
通过 `xdb_searcher search` 命令来测试 ip2region.xdb 的查询:
```
➜ golang git:(v2.0_xdb) ✗ ./searcher search
dbmaker test [command options]
./xdb_searcher search [command options]
options:
--db string ip2region binary xdb file path
```
例如:使用默认的 data/ip2region.xdb 进行查询测试
```bash
➜ golang git:(v2.0_xdb) ✗ ./searcher search --db=../../data/ip2region.xdb
ip2region 2.0 searcher test program, type `quit` to exit
➜ golang git:(v2.0_xdb) ✗ ./xdb_searcher search --db=../../data/ip2region.xdb
ip2region xdb searcher test program, type `quit` to exit
ip2region>> 1.2.3.4
{region:美国|0|华盛顿|0|谷歌, took:101.57µs}
```
@ -70,10 +70,10 @@ ip2region>> 1.2.3.4
# bench 测试
通过 `searcher bench` 命令来进行自动 bench 测试,一方便得到大量查询的效率一方便确保程序和xdb文件都没有错误
通过 `xdb_searcher bench` 命令来进行自动 bench 测试,一方面确保程序和xdb文件都没有错误一方面通过大量的查询得到平均查询性能
```bash
➜ golang git:(v2.0_xdb) ✗ ./searcher bench
searcher bench [command options]
➜ golang git:(v2.0_xdb) ✗ ./xdb_searcher bench
./xdb_searcher bench [command options]
options:
--db string ip2region binary xdb file path
--src string source ip text file path
@ -81,8 +81,8 @@ options:
例如:通过 data/ip2region.xdb 和 data/ip.merge.txt 进行 bench 测试:
```bash
➜ golang git:(v2.0_xdb) ✗ ./searcher bench --db=../../data/ip2region.xdb --src=../../data/ip.merge.txt
➜ golang git:(v2.0_xdb) ✗ ./xdb_searcher bench --db=../../data/ip2region.xdb --src=../../data/ip.merge.txt
Bench finished, {total: 3417955, took: 28.211578339s, cost: 8253 ns/op}
```
bench 程序会逐行读取 `src` 指定的源IP文件然后每个 IP 段选取 5 个固定位置的 IP 进行测试,以确保查询的 region 信息和原始的 region 信息是相同。测试途中没有调试信息的输出,有错误会打印错误信息并且终止运行,所以看到 `Bench finished` 就表示 bench 成功了cost 是表示每次查询操作的平均时间(ns)。
*请注意 bench 使用的 src 文件需要是生成对应的 xdb 文件的相同的源文件*。bench 程序会逐行读取 `src` 指定的源IP文件然后每个 IP 段选取 5 个固定位置的 IP 进行测试,以确保查询的 region 信息和原始的 region 信息是相同。测试途中没有调试信息的输出,有错误会打印错误信息并且终止运行,所以看到 `Bench finished` 就表示 bench 成功了cost 是表示每次查询操作的平均时间(ns)。

View File

@ -12,8 +12,8 @@ import (
)
func printHelp() {
fmt.Printf("ip2region searcher 2.0\n")
fmt.Printf("searcher [command] [command options]\n")
fmt.Printf("ip2region xdb searcher\n")
fmt.Printf("%s [command] [command options]\n", os.Args[0])
fmt.Printf("Command: \n")
fmt.Printf(" search search input test\n")
fmt.Printf(" bench search bench test\n")
@ -45,7 +45,7 @@ func testSearch() {
}
if dbFile == "" {
fmt.Printf("dbmaker test [command options]\n")
fmt.Printf("%s search [command options]\n", os.Args[0])
fmt.Printf("options:\n")
fmt.Printf(" --db string ip2region binary xdb file path\n")
return
@ -66,7 +66,7 @@ func testSearch() {
fmt.Printf("searcher test program exited, thanks for trying\n")
}()
fmt.Println("ip2region 2.0 searcher test program, type `quit` to exit")
fmt.Println("ip2region xdb searcher test program, type `quit` to exit")
reader := bufio.NewReader(os.Stdin)
for {
fmt.Print("ip2region>> ")
@ -122,7 +122,7 @@ func testBench() {
}
if dbFile == "" || srcFile == "" {
fmt.Printf("searcher bench [command options]\n")
fmt.Printf("%s bench [command options]\n", os.Args[0])
fmt.Printf("options:\n")
fmt.Printf(" --db string ip2region binary xdb file path\n")
fmt.Printf(" --src string source ip text file path\n")

View File

@ -14,7 +14,7 @@ go build -o xdb_maker
通过 `xdb_maker gen` 命令生成 ip2region.xdb 二进制文件:
```
➜ golang git:(v2.0_xdb) ✗ ./xdb_maker gen
xdb_maker gen [command options]
./xdb_maker gen [command options]
options:
--src string source ip text file path
--dst string destination binary xdb file path
@ -33,7 +33,8 @@ options:
通过 `xdb_maker search` 命令来测试查询输入的 ip
```
xdb_maker search [command options]
➜ golang git:(v2.0_xdb) ✗ ./xdb_maker search
./xdb_maker search [command options]
options:
--db string ip2region binary xdb file path
```
@ -61,7 +62,7 @@ ip2region>>
如果你自主生成了 xdb 文件,请确保运行如下的 `xdb_maker bench` 命令来确保生成的的 xdb 文件的正确性:
```
➜ golang git:(v2.0_xdb) ✗ ./xdb_maker bench
xdb_maker bench [command options]
./xdb_maker bench [command options]
options:
--db string ip2region binary xdb file path
--src string source ip text file path
@ -81,5 +82,5 @@ try to bench segment: `224.0.0.0|255.255.255.255|0|0|0|内网IP|内网IP`
|-try to bench ip '255.255.255.255' ... --[Ok]
Bench finished, {count: 3417955, failed: 0, took: 52.200116397s}
```
*请注意 bench 测试使用的 `src` 文件需要是对应的生成 ip2region.xdb 的源文件*。
*请注意 bench 测试使用的 `src` 文件需要是对应的生成 ip2region.xdb 的源文件相同*。
如果运行过程中有错误会立马停止运行,也可以执行 --ignore-error=true 参数来忽略错误,在最后看 failed 的统计结果。