Skip to content

Commit 9fa3000

Browse files
xiaoyumuxiCopilot
andcommitted
add:修改一下QPS压测的方式,跑出来TCP+protobuf方式的数据结果
Co-authored-by: Copilot <copilot@github.com>
1 parent f6a3c72 commit 9fa3000

5 files changed

Lines changed: 523 additions & 2 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,44 @@ Comparison of processing a standard POJO (`RpcRequest`).
197197
- **Protobuf vs. Java**: Protobuf is **77x faster** and **10x smaller** than standard Java serialization.
198198
- **Binary vs. Text**: Kryo (Binary) provides **6x higher throughput** than JSON (Text) for complex objects due to Varint compression and omission of field names.
199199

200+
#### 5.3 End-to-End Load Test (Business Simulation)
201+
202+
Use `LoadTestApp` to simulate microservice-style calls with configurable concurrency, duration, payload size, and output file. It reports QPS, P50/P95/P99 latency, error rate, and basic GC/heap stats.
203+
204+
**1) Build**
205+
206+
```bash
207+
mvn -pl rpc-consumer -am -DskipTests package
208+
```
209+
210+
**2) Start Provider**
211+
212+
```bash
213+
./run_server.sh
214+
```
215+
216+
**3) Run Load Test Client**
217+
218+
```bash
219+
java -cp rpc-consumer/target/rpc-consumer-1.0-SNAPSHOT.jar:rpc-transport-netty/target/rpc-transport-netty-1.0-SNAPSHOT.jar:rpc-core/target/rpc-core-1.0-SNAPSHOT.jar:rpc-common/target/rpc-common-1.0-SNAPSHOT.jar:rpc-api/target/rpc-api-1.0-SNAPSHOT.jar:$(mvn -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout -pl rpc-consumer -am) \
220+
com.xiaoyu.rpc.consumer.LoadTestApp \
221+
--threads=200 --warmup=5 --duration=30 --payload=128 --output=loadtest-results.txt
222+
```
223+
224+
**Parameters**
225+
- `--threads=NUM` Worker threads (default 200)
226+
- `--warmup=SEC` Warmup seconds (default 5)
227+
- `--duration=SEC` Measurement seconds (default 30)
228+
- `--payload=BYTES` Payload size in bytes (default 128)
229+
- `--sample-size=NUM` Latency sample size (default 1,000,000)
230+
- `--output=PATH` Output file path (default `loadtest-results.txt`)
231+
- `--append` Append to output file
232+
233+
**Output format (one line per run)**
234+
```
235+
time=2026-04-29T12:34:56Z threads=200 warmupSec=5 durationSec=30 payloadBytes=128 total=123456 success=123000 error=456 qps=4115.20 successQps=4100.00 errorRatePct=0.37 avgLatencyMs=0.410 minMs=0.120 p50Ms=0.300 p95Ms=0.900 p99Ms=1.500 maxMs=5.000 samples=1000000 heapUsedBytes=12345678 heapTotalBytes=268435456 gcCount=2 gcTimeMs=15
236+
```
237+
200238
---
201239

202240
## 🛠️ Configuration

README_ZH.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,44 @@ XiaoYu RPC 专注于极致性能。以下是使用 **JMH** 测得的真实数据
234234
- **Protobuf vs. Java**: Protobuf 的处理速度比 Java 原生序列化快 **77 倍**,且体积缩小了 **10 倍**
235235
- **二进制 vs. 文本**: 在处理复杂 POJO 时,二进制协议 (Kryo/Protobuf) 的吞吐量比文本协议 (JSON) 高出约 **6 倍**,这归功于 Varint 压缩和去除字段名存储。
236236

237+
#### 5.3 端到端负载测试(业务模拟)
238+
239+
为更贴近微服务调用场景,提供一个可配置的客户端压测入口 `LoadTestApp`,支持 QPS、P50/P95/P99、错误率及 GC/堆内存统计,并可直接写入文件。
240+
241+
**1) 构建**
242+
243+
```bash
244+
mvn -pl rpc-consumer -am -DskipTests package
245+
```
246+
247+
**2) 启动 Provider**
248+
249+
```bash
250+
./run_server.sh
251+
```
252+
253+
**3) 启动压测客户端**
254+
255+
```bash
256+
java -cp rpc-consumer/target/rpc-consumer-1.0-SNAPSHOT.jar:rpc-transport-netty/target/rpc-transport-netty-1.0-SNAPSHOT.jar:rpc-core/target/rpc-core-1.0-SNAPSHOT.jar:rpc-common/target/rpc-common-1.0-SNAPSHOT.jar:rpc-api/target/rpc-api-1.0-SNAPSHOT.jar:$(mvn -q dependency:build-classpath -Dmdep.outputFile=/dev/stdout -pl rpc-consumer -am) \
257+
com.xiaoyu.rpc.consumer.LoadTestApp \
258+
--threads=200 --warmup=5 --duration=30 --payload=128 --output=loadtest-results.txt
259+
```
260+
261+
**参数说明**
262+
- `--threads=NUM` 并发线程数(默认 200)
263+
- `--warmup=SEC` 预热秒数(默认 5)
264+
- `--duration=SEC` 采样秒数(默认 30)
265+
- `--payload=BYTES` 请求字符串大小(默认 128)
266+
- `--sample-size=NUM` 延迟采样容量(默认 1,000,000)
267+
- `--output=PATH` 输出文件路径(默认 `loadtest-results.txt`
268+
- `--append` 追加写入文件
269+
270+
**输出文件格式(每行一条记录)**
271+
```
272+
time=2026-04-29T12:34:56Z threads=200 warmupSec=5 durationSec=30 payloadBytes=128 total=123456 success=123000 error=456 qps=4115.20 successQps=4100.00 errorRatePct=0.37 avgLatencyMs=0.410 minMs=0.120 p50Ms=0.300 p95Ms=0.900 p99Ms=1.500 maxMs=5.000 samples=1000000 heapUsedBytes=12345678 heapTotalBytes=268435456 gcCount=2 gcTimeMs=15
273+
```
274+
237275
---
238276

239277
## 🛠️ 配置手册

loadtest-results.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
time=2026-04-29T09:00:45.247089Z threads=200 warmupSec=5 durationSec=30 payloadBytes=128 total=471906 success=471906 error=0 qps=15721.79 successQps=15721.79 errorRatePct=0.00 avgLatencyMs=12.716 minMs=5.266 p50Ms=11.371 p95Ms=18.914 p99Ms=24.701 maxMs=41.989 samples=471906 heapUsedBytes=161613048 heapTotalBytes=239075328 gcCount=68 gcTimeMs=72

0 commit comments

Comments
 (0)