Skip to content

Commit f3d015e

Browse files
committed
test: add resource benchmark test example
1 parent 6203b55 commit f3d015e

File tree

15 files changed

+1277
-1
lines changed

15 files changed

+1277
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ coverage.html
6767
coverage.txt
6868

6969
pkg/adapters/eino/*_test.go
70-
pkg/adapters/langchaingo/*_test.go
70+
pkg/adapters/langchaingo/*_test.go
71+
72+
.env
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu:22.04
2+
3+
4+
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list \
5+
&& sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
6+
7+
RUN apt-get update && \
8+
apt-get install -y vim net-tools ca-certificates less redis-tools && \
9+
apt-get clean && \
10+
rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /workspace
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/zsh
2+
3+
mkdir -p ./out
4+
5+
# 编译go代码
6+
go build -o out/llm_token_ratelimit_benchmark main.go
7+
# 复制 sentinel 配置文件到输出目录
8+
cp sentinel.yml out/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/zsh
2+
3+
echo "Building application..."
4+
./build-code.sh
5+
6+
echo "Building and starting containers..."
7+
docker-compose -f docker-compose.yml down
8+
docker-compose -f docker-compose.yml up --build -d
9+
10+
echo "Waiting for Redis nodes to start..."
11+
sleep 10
12+
13+
echo "Checking Redis nodes status..."
14+
for port in 7001 7002 7003; do
15+
echo "Checking Redis on port $port..."
16+
timeout 5 redis-cli -h 127.0.0.1 -p $port ping || echo "Redis on port $port not ready"
17+
done
18+
19+
echo "Initializing Redis cluster..."
20+
# 使用容器内部执行集群初始化
21+
docker exec redis-node-1 redis-cli --cluster create \
22+
172.20.0.11:6379 \
23+
172.20.0.12:6379 \
24+
172.20.0.13:6379 \
25+
--cluster-replicas 0 \
26+
--cluster-yes
27+
28+
echo "Checking cluster status..."
29+
docker exec redis-node-1 redis-cli cluster nodes
30+
31+
echo "Cluster setup complete!"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
services:
2+
# Redis 6.0 集群(三主三从)
3+
redis-node-1:
4+
image: redis:6.2.7
5+
container_name: redis-node-1
6+
ports:
7+
- "7001:6379"
8+
- "17001:16379"
9+
volumes:
10+
- ./redis.conf:/usr/local/etc/redis/redis.conf
11+
command: redis-server /usr/local/etc/redis/redis.conf
12+
networks:
13+
test-network:
14+
ipv4_address: 172.20.0.11
15+
16+
redis-node-2:
17+
image: redis:6.2.7
18+
container_name: redis-node-2
19+
ports:
20+
- "7002:6379"
21+
- "17002:16379"
22+
volumes:
23+
- ./redis.conf:/usr/local/etc/redis/redis.conf
24+
command: redis-server /usr/local/etc/redis/redis.conf
25+
networks:
26+
test-network:
27+
ipv4_address: 172.20.0.12
28+
29+
redis-node-3:
30+
image: redis:6.2.7
31+
container_name: redis-node-3
32+
ports:
33+
- "7003:6379"
34+
- "17003:16379"
35+
volumes:
36+
- ./redis.conf:/usr/local/etc/redis/redis.conf
37+
command: redis-server /usr/local/etc/redis/redis.conf
38+
networks:
39+
test-network:
40+
ipv4_address: 172.20.0.13
41+
42+
# Sentinel Go LLM Token RateLimit 服务容器
43+
sentinel-go-llm-token-ratelimit:
44+
build:
45+
context: .
46+
dockerfile: Dockerfile
47+
container_name: sentinel-go-llm-token-ratelimit
48+
command: ["tail", "-f", "/dev/null"]
49+
ports:
50+
- "9527:9527"
51+
volumes:
52+
- ./out:/workspace
53+
networks:
54+
- test-network
55+
depends_on:
56+
- redis-node-1
57+
- redis-node-2
58+
- redis-node-3
59+
environment:
60+
- LLM_API_KEY=${LLM_API_KEY}
61+
- LLM_BASE_URL=${LLM_BASE_URL}
62+
- LLM_MODEL=${LLM_MODEL}
63+
deploy:
64+
resources:
65+
limits:
66+
cpus: '2'
67+
memory: 4G
68+
restart: on-failure
69+
70+
# 定义网络和卷
71+
networks:
72+
test-network:
73+
driver: bridge
74+
ipam:
75+
config:
76+
- subnet: 172.20.0.0/16
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
module llm_token_ratelimit
2+
3+
go 1.22.0
4+
5+
replace github.com/alibaba/sentinel-golang => ../../../
6+
7+
require (
8+
github.com/alibaba/sentinel-golang v1.0.4
9+
github.com/cloudwego/eino v0.4.7
10+
github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250904121005-ad78ed3e5e49
11+
github.com/gin-gonic/gin v1.10.1
12+
github.com/tmc/langchaingo v0.1.13
13+
)
14+
15+
require (
16+
github.com/bahlo/generic-list-go v0.2.0 // indirect
17+
github.com/beorn7/perks v1.0.1 // indirect
18+
github.com/buger/jsonparser v1.1.1 // indirect
19+
github.com/bytedance/sonic v1.14.0 // indirect
20+
github.com/bytedance/sonic/loader v0.3.0 // indirect
21+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
22+
github.com/cloudwego/base64x v0.1.5 // indirect
23+
github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250826113018-8c6f6358d4bb // indirect
24+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
25+
github.com/dlclark/regexp2 v1.10.0 // indirect
26+
github.com/dustin/go-humanize v1.0.1 // indirect
27+
github.com/eino-contrib/jsonschema v1.0.0 // indirect
28+
github.com/evanphx/json-patch v0.5.2 // indirect
29+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
30+
github.com/getkin/kin-openapi v0.118.0 // indirect
31+
github.com/gin-contrib/sse v0.1.0 // indirect
32+
github.com/go-ole/go-ole v1.2.6 // indirect
33+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
34+
github.com/go-openapi/swag v0.22.4 // indirect
35+
github.com/go-playground/locales v0.14.1 // indirect
36+
github.com/go-playground/universal-translator v0.18.1 // indirect
37+
github.com/go-playground/validator/v10 v10.20.0 // indirect
38+
github.com/go-redis/redis/v8 v8.11.0 // indirect
39+
github.com/goccy/go-json v0.10.2 // indirect
40+
github.com/golang/protobuf v1.5.4 // indirect
41+
github.com/google/uuid v1.6.0 // indirect
42+
github.com/goph/emperror v0.17.2 // indirect
43+
github.com/invopop/yaml v0.1.0 // indirect
44+
github.com/jinzhu/copier v0.4.0 // indirect
45+
github.com/josharian/intern v1.0.0 // indirect
46+
github.com/json-iterator/go v1.1.12 // indirect
47+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
48+
github.com/leodido/go-urn v1.4.0 // indirect
49+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
50+
github.com/mailru/easyjson v0.7.7 // indirect
51+
github.com/mattn/go-isatty v0.0.20 // indirect
52+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
53+
github.com/meguminnnnnnnnn/go-openai v0.0.0-20250821095446-07791bea23a0 // indirect
54+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
55+
github.com/modern-go/reflect2 v1.0.2 // indirect
56+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
57+
github.com/nikolalohinski/gonja v1.5.3 // indirect
58+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
59+
github.com/perimeterx/marshmallow v1.1.4 // indirect
60+
github.com/pkg/errors v0.9.1 // indirect
61+
github.com/pkoukk/tiktoken-go v0.1.7 // indirect
62+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
63+
github.com/prometheus/client_golang v1.16.0 // indirect
64+
github.com/prometheus/client_model v0.3.0 // indirect
65+
github.com/prometheus/common v0.42.0 // indirect
66+
github.com/prometheus/procfs v0.10.1 // indirect
67+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
68+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
69+
github.com/sirupsen/logrus v1.9.3 // indirect
70+
github.com/slongfield/pyfmt v0.0.0-20220222012616-ea85ff4c361f // indirect
71+
github.com/spaolacci/murmur3 v1.1.0 // indirect
72+
github.com/tklauser/go-sysconf v0.3.12 // indirect
73+
github.com/tklauser/numcpus v0.6.1 // indirect
74+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
75+
github.com/ugorji/go/codec v1.2.12 // indirect
76+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
77+
github.com/yargevad/filepathx v1.0.0 // indirect
78+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
79+
golang.org/x/arch v0.11.0 // indirect
80+
golang.org/x/crypto v0.31.0 // indirect
81+
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
82+
golang.org/x/net v0.25.0 // indirect
83+
golang.org/x/sys v0.28.0 // indirect
84+
golang.org/x/text v0.21.0 // indirect
85+
google.golang.org/protobuf v1.34.1 // indirect
86+
gopkg.in/yaml.v2 v2.4.0 // indirect
87+
gopkg.in/yaml.v3 v3.0.1 // indirect
88+
)

0 commit comments

Comments
 (0)