From b1eb00e25e9356bd634915d3c69c100a87263a14 Mon Sep 17 00:00:00 2001 From: Alice39s Date: Sun, 28 Jun 2026 05:10:10 +0900 Subject: [PATCH] docs(erlang): update READMEs with IPv6 examples and benchmark output --- binding/erlang/README.md | 32 +++++++++++----------- binding/erlang/README_zh.md | 53 +++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/binding/erlang/README.md b/binding/erlang/README.md index 36a4199..3280193 100644 --- a/binding/erlang/README.md +++ b/binding/erlang/README.md @@ -1,10 +1,10 @@ :globe_with_meridians: [中文简体](README_zh.md) | [English](README.md) -# ip2region erlang query client +# ip2region Erlang query client ### 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. +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 @@ -43,7 +43,7 @@ The `xdb:search/1` interface automatically detects IPv4 and IPv6 inputs and rout ### Compile -``` +```bash $ rebar3 compile ``` @@ -51,13 +51,13 @@ $ rebar3 compile Place the xdb file in the `priv` directory, then start the Erlang node: -``` +```bash $ 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: -``` +```erlang 1> xdb:search("1.0.8.0"). [20013,22269,124,24191,19996,30465,124,24191,24030,24066, 124,20013,22269,30005,20449,124,67,78] @@ -74,7 +74,7 @@ Call the `xdb:search/1` interface in the Erlang shell to query IP address inform With dual-stack enabled, IPv6 addresses are supported in the same way: -``` +```erlang 1> io:format("~ts~n", [xdb:search("2001:4860:4860::8888")]). United States|Florida|Miami|Google LLC|US 2> io:format("~ts~n", [xdb:search(<<"2001:4860:4860::8888">>)]). @@ -85,21 +85,21 @@ United States|Florida|Miami|Google LLC|US ### Usage -* Add the dependency in `rebar.config` +- Add the dependency in `rebar.config` -``` +```erlang {deps, [ ip2region ]}. ``` -* Start the ip2region Application +- Start the ip2region Application ```erlang {ok, _} = application:ensure_all_started(ip2region). ``` -* Call the `xdb:search/1` interface to query IP information +- Call the `xdb:search/1` interface to query IP information ```erlang xdb:search("1.0.8.0"). @@ -107,7 +107,7 @@ xdb:search("1.0.8.0"). ### Unit Test -``` +```bash $ rebar3 eunit ===> Verifying dependencies... ===> Analyzing applications... @@ -129,27 +129,27 @@ Both IPv4 and IPv6 benchmarks share the same script. Run it with the desired IP > result is written into the ETS cache. `warm` = second pass over the same list, > where every lookup is served directly from the ETS cache. -``` +```bash $ cd benchmarks/ $ sh xdb-benchmark.sh ipv4 ``` For IPv6: -``` +```bash $ sh xdb-benchmark.sh ipv6 ``` Or use the Makefile targets from the `binding/erlang` directory: -``` +```bash $ make bench-v4 $ make bench-v6 ``` #### IPv4 benchmark example -``` +```bash System: CPU : Apple M4 Cores : 10 cores / 10 threads @@ -165,7 +165,7 @@ Done. #### IPv6 benchmark example -``` +```bash System: CPU : Apple M4 Cores : 10 cores / 10 threads diff --git a/binding/erlang/README_zh.md b/binding/erlang/README_zh.md index c5b5b45..faba2db 100644 --- a/binding/erlang/README_zh.md +++ b/binding/erlang/README_zh.md @@ -1,13 +1,16 @@ :globe_with_meridians: [中文简体](README_zh.md) | [English](README.md) -# ip2region erlang 查询客户端 +# ip2region Erlang 查询客户端 ### 简介 -该bingding以erlang语言实现xdb查询客户端,基于Erlang OTP Application,查询逻辑由ip2region_worker工作进程实现,支持配多个工作进程来进行负载均衡。 + +该 bingding 以 `Erlang` 语言实现 xdb 查询客户端,基于 `Erlang OTP Application`,查询逻辑由 `ip2region_worker` 工作进程实现,支持配多个工作进程来进行负载均衡。 ### 应用配置 -该应用可配置的参数在ip2region.app.src中,如下: -``` erlang + +该应用可配置的参数在 `ip2region.app.src` 中, 如下: + +```erlang {env,[ {poolargs, [ {size, 1}, %% 工作进程默认数量 @@ -23,7 +26,7 @@ 如需启用 IPv6 查询,在 `db` 列表中加入 `ipv6` 项,并将两个 xdb 文件放到 `priv/` 目录下: -``` erlang +```erlang {env,[ {poolargs, [ {size, 1}, @@ -40,17 +43,21 @@ ### 编译 -``` +```bash $ rebar3 compile ``` ### 运行 -将xdb文件放到priv目录下,然后启动erlang节点: -``` + +将 xdb 文件放到 `priv` 目录下,然后启动 Erlang 节点: + +```bash $ rebar3 shell ``` + 在 Erlang shell 中调用 `xdb:search/1` 接口查询 IP 地址信息。该接口支持 list 字符串、binary 字符串、tuple 和整数表示的 IP 地址: -``` + +```erlang 1> xdb:search("1.0.8.0"). [20013,22269,124,24191,19996,30465,124,24191,24030,24066, 124,20013,22269,30005,20449,124,67,78] @@ -66,7 +73,8 @@ $ rebar3 shell ``` 启用双栈后,IPv6 地址也按同样方式支持: -``` + +```erlang 1> io:format("~ts~n", [xdb:search("2001:4860:4860::8888")]). United States|Florida|Miami|Google LLC|US 2> io:format("~ts~n", [xdb:search(<<"2001:4860:4860::8888">>)]). @@ -76,25 +84,30 @@ United States|Florida|Miami|Google LLC|US ``` ### 使用方法 -* 在rebar.config中引入依赖 -``` + +- 在 `rebar.config` 中引入依赖 + +```erlang {deps, [ ip2region ]}. ``` -* 启动 ip2region Application + +- 启动 ip2region Application + ```erlang {ok, _} = application:ensure_all_started(ip2region). ``` -* 调用 `xdb:search/1` 接口查询 IP 信息 +- 调用 `xdb:search/1` 接口查询 IP 信息 + ```erlang xdb:search("1.0.8.0"). ``` ### 单元测试 -``` +```bash $ rebar3 eunit ===> Verifying dependencies... ===> Analyzing applications... @@ -115,27 +128,27 @@ IPv4 与 IPv6 共用一个脚本,通过参数指定版本: > `cold` = 第一次遍历源文件:每个 IP 都会触发真实查询,并把结果写入 ETS 缓存。 > `warm` = 第二次遍历同一列表,所有查询都直接命中 ETS 缓存。 -``` +```bash $ cd benchmarks/ $ sh xdb-benchmark.sh ipv4 ``` IPv6: -``` +```bash $ sh xdb-benchmark.sh ipv6 ``` 也可以在 `binding/erlang` 目录直接用 Makefile: -``` +```bash $ make bench-v4 $ make bench-v6 ``` #### IPv4 基准测试示例 -``` +```bash System: CPU : Apple M4 Cores : 10 cores / 10 threads @@ -151,7 +164,7 @@ Done. #### IPv6 基准测试示例 -``` +```bash System: CPU : Apple M4 Cores : 10 cores / 10 threads