From 81885a16cf52466c190447b9deab59f0d9ce9976 Mon Sep 17 00:00:00 2001 From: lionsoul2014 Date: Wed, 25 Feb 2026 20:07:35 +0800 Subject: [PATCH 1/2] add english readme for erlang binding --- README.md | 26 ++++---- README_zh.md | 26 ++++---- binding/erlang/README.md | 61 ++++++++++------- binding/erlang/README_zh.md | 128 ++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 50 deletions(-) create mode 100644 binding/erlang/README_zh.md diff --git a/README.md b/README.md index c96db39..a181d6f 100644 --- a/README.md +++ b/README.md @@ -37,19 +37,19 @@ For API introductions, usage documentation, and test programs, please refer to t | Language | Description | IPv4 Support | IPv6 Support | | --- | --- | --- | --- | -| [Golang](binding/golang/README.md) | golang xdb query client | :white_check_mark: | :white_check_mark: | -| [PHP](binding/php/README.md) | php xdb query client | :white_check_mark: | :white_check_mark: | -| [Java](binding/java/README.md) | java xdb query client | :white_check_mark: | :white_check_mark: | -| [C](binding/c/README.md) | POSIX C xdb query client | :white_check_mark: | :white_check_mark: | -| [Lua_c](binding/lua_c/README.md) | lua c extension xdb query client | :white_check_mark: | :white_check_mark: | -| [Lua](binding/lua/README.md) | lua xdb query client | :white_check_mark: | :white_check_mark: | -| [Rust](binding/rust/README.md) | rust xdb query client | :white_check_mark: | :white_check_mark: | -| [Python](binding/python/README.md) | python xdb query client | :white_check_mark: | :white_check_mark: | -| [Javascript](binding/javascript/README.md) | javascript xdb query client | :white_check_mark: | :white_check_mark: | -| [Csharp](binding/csharp) | csharp xdb query client | :white_check_mark: | :white_check_mark: | -| [Erlang](binding/erlang) | erlang xdb query client | :white_check_mark: | :x: | -| [Nginx](binding/nginx) | nginx extension xdb query client | :white_check_mark: | :x: | -| [C++](binding/cpp) | C++ xdb query client | :white_check_mark: | :white_check_mark: | +| [Golang](binding/golang/README.md) | golang query client | :white_check_mark: | :white_check_mark: | +| [PHP](binding/php/README.md) | php query client | :white_check_mark: | :white_check_mark: | +| [Java](binding/java/README.md) | java query client | :white_check_mark: | :white_check_mark: | +| [C](binding/c/README.md) | C[std=c99] query client | :white_check_mark: | :white_check_mark: | +| [Lua_c](binding/lua_c/README.md) | lua c extension query client | :white_check_mark: | :white_check_mark: | +| [Lua](binding/lua/README.md) | lua query client | :white_check_mark: | :white_check_mark: | +| [Rust](binding/rust/README.md) | rust query client | :white_check_mark: | :white_check_mark: | +| [Python](binding/python/README.md) | python query client | :white_check_mark: | :white_check_mark: | +| [Javascript](binding/javascript/README.md) | javascript query client | :white_check_mark: | :white_check_mark: | +| [Csharp](binding/csharp) | csharp query client | :white_check_mark: | :white_check_mark: | +| [Erlang](binding/erlang/README.md) | erlang query client | :white_check_mark: | :x: | +| [Nginx](binding/nginx) | nginx extension query client | :white_check_mark: | :x: | +| [C++](binding/cpp) | C++ query client | :white_check_mark: | :white_check_mark: | The following toolchain implementations are contributed by community developers via third-party repositories: diff --git a/README_zh.md b/README_zh.md index d780cec..177988c 100644 --- a/README_zh.md +++ b/README_zh.md @@ -36,19 +36,19 @@ API 介绍,使用文档和测试程序请参考对应 `searcher` 查询客户端下的 README 介绍,全部查询 binding 实现情况如下: | 编程语言 | 描述 | IPv4 支持 | IPv6 支持 | | --- | --- | --- | --- | -| [Golang](binding/golang/README_zh.md) | golang xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [PHP](binding/php/README_zh.md) | php xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Java](binding/java/README_zh.md) | java xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [C](binding/c/README_zh.md) | POSIX C xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Lua_c](binding/lua_c/README_zh.md) | lua c 扩展 xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Lua](binding/lua/README_zh.md) | lua xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Rust](binding/rust/README_zh.md) | rust xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Python](binding/python/README_zh.md) | python xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Javascript](binding/javascript/README_zh.md) | javascript xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Csharp](binding/csharp) | csharp xdb 查询客户端 | :white_check_mark: | :white_check_mark: | -| [Erlang](binding/erlang) | erlang xdb 查询客户端 | :white_check_mark: | :x: | -| [Nginx](binding/nginx) | nginx 扩展 xdb 查询客户端 | :white_check_mark: | :x: | -| [C++](binding/cpp) | C++ xdb 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Golang](binding/golang/README_zh.md) | golang 查询客户端 | :white_check_mark: | :white_check_mark: | +| [PHP](binding/php/README_zh.md) | php 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Java](binding/java/README_zh.md) | java 查询客户端 | :white_check_mark: | :white_check_mark: | +| [C](binding/c/README_zh.md) | C[std=c99] 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Lua_c](binding/lua_c/README_zh.md) | lua c 扩展查询客户端 | :white_check_mark: | :white_check_mark: | +| [Lua](binding/lua/README_zh.md) | lua 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Rust](binding/rust/README_zh.md) | rust 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Python](binding/python/README_zh.md) | python 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Javascript](binding/javascript/README_zh.md) | javascript 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Csharp](binding/csharp) | csharp 查询客户端 | :white_check_mark: | :white_check_mark: | +| [Erlang](binding/erlang/README_zh.md) | erlang 查询客户端 | :white_check_mark: | :x: | +| [Nginx](binding/nginx) | nginx 扩展查询客户端 | :white_check_mark: | :x: | +| [C++](binding/cpp) | C++ xdb 查询客户端 | :white_check_mark: | :white_check_mark: | 以下工具链实现由社区开发者通过第三方仓库贡献: diff --git a/binding/erlang/README.md b/binding/erlang/README.md index b3628c7..7077ca5 100644 --- a/binding/erlang/README.md +++ b/binding/erlang/README.md @@ -1,31 +1,41 @@ -# ip2region xdb erlang 查询客户端 +:globe_with_meridians: [中文简体](README_zh.md) | [English](README.md) -### 简介 -该bingding以erlang语言实现xdb查询客户端,基于Erlang OTP Application,查询逻辑由ip2region_worker工作进程实现,支持配多个工作进程来进行负载均衡。 +# ip2region erlang query client -### 应用配置 -该应用可配置的参数在ip2region.app.src中,如下: -``` erlang +### Introduction + +This binding implements the xdb query client in Erlang, based on the Erlang OTP Application. The query logic is implemented by the `ip2region_worker` worker process, supporting multiple worker processes for load balancing. + +### Application Configuration + +The configurable parameters for this application are in `ip2region.app.src`, as follows: + +```erlang {env,[ {poolargs, [ - {size, 1}, %% 工作进程默认数量 - {max_overflow, 5} %% 工作进程最大数量 + {size, 1}, %% Default number of worker processes + {max_overflow, 5} %% Maximum number of worker processes ]} ]} ``` -### 编译 +### Compile ``` $ rebar3 compile -``` -### 运行 -将xdb文件放到priv目录下,然后启动erlang节点: -``` -$ rebar3 shell ``` -在erlang shell中调用xdb:search/1接口查询Ip地址信息, 该接口支持以list格式字符串、binary格式字符串、tuple和整数表示的IP地址,如下: + +### Run + +Place the xdb file in the `priv` directory, then start the Erlang node: + +``` +$ rebar3 shell +``` + +Call the `xdb:search/1` interface in the Erlang shell to query IP address information. This interface supports IP addresses represented as list strings, binary strings, tuples, and integers, as follows: + ``` 1> xdb:search("1.0.8.0"). [20013,22269,124,48,124,24191,19996,30465,124,24191,24030, @@ -41,15 +51,18 @@ io:format("~ts~n", [xdb:search(<<"1.0.8.0">>)]). 中国|0|广东省|广州市|电信 ``` -### 使用方法 -* 在rebar.config中引入依赖 +### Usage + +* Add the dependency in `rebar.config` + ``` {deps, [ ip2region ]}. - ``` -* 启动ip2region Application + +* Start the ip2region Application + ``` ...... @@ -58,7 +71,8 @@ application:ensure_started(ip2region), ...... ``` -* 调用xdb:search/1接口查询IP信息 +* Call the `xdb:search/1` interface to query IP information + ``` ...... @@ -67,7 +81,7 @@ ip2region:search("1.0.8.0"), ...... ``` -### 单元测试 +### Unit Test ``` $ rebar3 eunit @@ -81,10 +95,10 @@ XdbFile:/home/admin/erl-workspace/ip2region/binding/erlang/_build/test/lib/ip2re .... Finished in 0.074 seconds 4 tests, 0 failures - ``` -### 基准测试 +### Benchmark + ``` $ cd benchmarks/ $ sh xdb-benchmark.sh @@ -125,5 +139,4 @@ search 1017926.4395259906 times per second, use 0.9823892583688677 micro second per search benchmark test finish - ``` diff --git a/binding/erlang/README_zh.md b/binding/erlang/README_zh.md new file mode 100644 index 0000000..7663d47 --- /dev/null +++ b/binding/erlang/README_zh.md @@ -0,0 +1,128 @@ +:globe_with_meridians: [中文简体](README_zh.md) | [English](README.md) + +# ip2region erlang 查询客户端 + +### 简介 +该bingding以erlang语言实现xdb查询客户端,基于Erlang OTP Application,查询逻辑由ip2region_worker工作进程实现,支持配多个工作进程来进行负载均衡。 + +### 应用配置 +该应用可配置的参数在ip2region.app.src中,如下: +``` erlang + {env,[ + {poolargs, [ + {size, 1}, %% 工作进程默认数量 + {max_overflow, 5} %% 工作进程最大数量 + ]} + ]} +``` + +### 编译 + +``` +$ rebar3 compile +``` +### 运行 +将xdb文件放到priv目录下,然后启动erlang节点: +``` +$ rebar3 shell + +``` +在erlang shell中调用xdb:search/1接口查询Ip地址信息, 该接口支持以list格式字符串、binary格式字符串、tuple和整数表示的IP地址,如下: +``` +1> xdb:search("1.0.8.0"). +[20013,22269,124,48,124,24191,19996,30465,124,24191,24030, + 24066,124,30005,20449] +2> +3> io:format("~ts~n", [xdb:search("1.0.8.0")]). +中国|0|广东省|广州市|电信 +io:format("~ts~n", [xdb:search(<<"1.0.8.0">>)]). +中国|0|广东省|广州市|电信 +4> io:format("~ts~n", [xdb:search({1,0,8,0})]). +中国|0|广东省|广州市|电信 +6> io:format("~ts~n", [xdb:search(16779264)]). +中国|0|广东省|广州市|电信 +``` + +### 使用方法 +* 在rebar.config中引入依赖 +``` +{deps, [ + ip2region +]}. +``` +* 启动ip2region Application +``` +...... + +application:ensure_started(ip2region), + +...... +``` + +* 调用xdb:search/1接口查询IP信息 +``` +...... + +ip2region:search("1.0.8.0"), + +...... +``` + +### 单元测试 + +``` +$ rebar3 eunit +===> Verifying dependencies... +===> Analyzing applications... +===> Compiling ip2region +===> Performing EUnit tests... +=INFO REPORT==== 17-Jan-2023::11:52:59.920155 === +XdbFile:/home/admin/erl-workspace/ip2region/binding/erlang/_build/test/lib/ip2region/priv/ip2region.xdb + +.... +Finished in 0.074 seconds +4 tests, 0 failures +``` + +### 基准测试 +``` +$ cd benchmarks/ +$ sh xdb-benchmark.sh +===> Verifying dependencies... +===> Analyzing applications... +===> Compiling ip2region +Erlang/OTP 24 [erts-12.3.2.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit] + +Eshell V12.3.2.2 (abort with ^G) +1> =INFO REPORT==== 17-Jan-2023::11:37:35.631095 === +XdbFile:/home/admin/erl-workspace/ip2region/binding/erlang/_build/default/lib/ip2region/priv/ip2region.xdb + +===> Booted ip2region +===> Evaluating: "xdb_benchmark:main(\"../../data/ip.merge.txt\"), init:stop()." +CPU info: +model name : AMD EPYC 7K62 48-Core Processor +cache size : 512 KB +cpu MHz : 2595.124 +bogomips : 5190.24 +cores/threads : 2 + +Erlang info: +system_version:Erlang/OTP 24 [erts-12.3.2.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit] +load test data use 4.835593s + +start run benchmark tests + +search from file: +ip count:683844, +total time: 28.201699s, +search 24248.326315375536 times per second, +use 41.23995969841075 micro second per search + +search from cache: +ip count:683844, +total time: 0.671801s, +search 1017926.4395259906 times per second, +use 0.9823892583688677 micro second per search + +benchmark test finish +``` From b3115ba7aa3d5aad78f66fe27cbb719daefaade0 Mon Sep 17 00:00:00 2001 From: lionsoul2014 Date: Wed, 25 Feb 2026 20:12:14 +0800 Subject: [PATCH 2/2] adjust the layout --- binding/erlang/README.md | 1 - binding/erlang/README_zh.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/binding/erlang/README.md b/binding/erlang/README.md index 7077ca5..08b9999 100644 --- a/binding/erlang/README.md +++ b/binding/erlang/README.md @@ -23,7 +23,6 @@ The configurable parameters for this application are in `ip2region.app.src`, as ``` $ rebar3 compile - ``` ### Run diff --git a/binding/erlang/README_zh.md b/binding/erlang/README_zh.md index 7663d47..0ebc6d6 100644 --- a/binding/erlang/README_zh.md +++ b/binding/erlang/README_zh.md @@ -21,11 +21,11 @@ ``` $ rebar3 compile ``` + ### 运行 将xdb文件放到priv目录下,然后启动erlang节点: ``` $ rebar3 shell - ``` 在erlang shell中调用xdb:search/1接口查询Ip地址信息, 该接口支持以list格式字符串、binary格式字符串、tuple和整数表示的IP地址,如下: ```