Files
huang 931e140e8e
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m35s
feat: 实现 IoT 卡轮询系统(支持千万级卡规模)
实现功能:
- 实名状态检查轮询(可配置间隔)
- 卡流量检查轮询(支持跨月流量追踪)
- 套餐检查与超额自动停机
- 分布式并发控制(Redis 信号量)
- 手动触发轮询(单卡/批量/条件筛选)
- 数据清理配置与执行
- 告警规则与历史记录
- 实时监控统计(队列/性能/并发)

性能优化:
- Redis 缓存卡信息,减少 DB 查询
- Pipeline 批量写入 Redis
- 异步流量记录写入
- 渐进式初始化(10万卡/批)

压测工具(scripts/benchmark/):
- Mock Gateway 模拟上游服务
- 测试卡生成器
- 配置初始化脚本
- 实时监控脚本

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 17:32:44 +08:00

55 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 轮询系统压测指南
## 目标
模拟 1000 万张卡的轮询场景,测试系统性能。
## 环境要求
- Docker运行本地 Redis
- 测试环境 PostgreSQL已有
- 10+ CPU 核心
- 16GB+ 内存
## 压测步骤
### Step 1: 启动本地 Redis
```bash
./scripts/benchmark/start_redis.sh
```
### Step 2: 启动 Mock Gateway模拟上游接口
```bash
go run ./scripts/benchmark/mock_gateway.go
```
### Step 3: 生成测试数据1000万张卡
```bash
go run ./scripts/benchmark/generate_cards.go
```
### Step 4: 启动 Worker 进行压测
```bash
# 使用本地 Redis 配置 + Mock Gateway
source .env.local && \
JUNHONG_REDIS_ADDRESS=127.0.0.1 \
JUNHONG_REDIS_PORT=6379 \
JUNHONG_REDIS_PASSWORD="" \
JUNHONG_REDIS_DB=0 \
JUNHONG_GATEWAY_BASE_URL=http://127.0.0.1:8888 \
JUNHONG_GATEWAY_APP_ID=test \
JUNHONG_GATEWAY_APP_SECRET=testsecret123456 \
JUNHONG_GATEWAY_TIMEOUT=30 \
go run ./cmd/worker/...
```
**注意**:可以启动多个 Worker 实例来增加并发处理能力。单个 Worker 通过 Asynq 已支持并发任务处理。
### Step 5: 监控压测状态
```bash
./scripts/benchmark/monitor.sh
```
## 预期结果
- 初始化时间:~50秒1000万卡
- 调度吞吐5万张/秒
- 任务处理:取决于 Gateway 响应时间