test-suite/seata-benchmark-cli/README.md
A command-line benchmark tool for stress testing Seata transaction modes.
--branches 0): Pure Seata protocol overhead testing--branches N): Actual distributed transaction executionsimple and ordermock and dbinventory, payment, and order--saga-random-seed--saga-timeout-step and --saga-timeout-mscd test-suite/seata-benchmark-cli
../../mvnw clean package
The executable JAR will be created at target/seata-benchmark-cli.jar
# AT mode benchmark (empty transaction)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--threads 1 \
--duration 60
# TCC mode benchmark (empty transaction)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode TCC \
--tps 100 \
--threads 1 \
--duration 60
# SAGA mode benchmark (empty transaction)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--threads 1 \
--duration 60
# SAGA_ANNOTATION mode benchmark (empty transaction)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA_ANNOTATION \
--tps 100 \
--threads 1 \
--duration 60
# XA mode benchmark (empty transaction)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode XA \
--tps 100 \
--threads 1 \
--duration 60
# AT mode with real MySQL transactions (via Testcontainers)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3
# TCC mode with real try/confirm/cancel
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode TCC \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3
# SAGA mode with state machine engine
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--rollback-percentage 5
# SAGA mode with explicit order state machine shape
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--saga-shape order
# SAGA mode with DB-backed business actions (via Testcontainers MySQL)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--saga-shape order \
--saga-workload db
# SAGA mode with payment-step failure injection
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--rollback-percentage 20 \
--saga-fail-step payment
# SAGA mode with reproducible payment-step failure injection
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--duration 60 \
--branches 3 \
--saga-shape order \
--rollback-percentage 20 \
--saga-fail-step payment \
--saga-random-seed 123
# SAGA mode with payment-step timeout simulation
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 10 \
--threads 1 \
--duration 10 \
--branches 3 \
--saga-shape order \
--saga-timeout-step payment \
--saga-timeout-ms 3000
# XA mode with real MySQL XA branches (via Testcontainers)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode XA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3
The benchmark CLI supports two primary testing modes:
--threads)--tps 100000) to avoid rate limitingExample:
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--threads 50 \
--tps 100000 \
--duration 60
--tps)--threads 1)Example:
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 500 \
--threads 1 \
--duration 60
Note: Avoid using both fixed TPS and multiple threads simultaneously, as this leads to unclear test semantics. The benchmark will reject such configurations.
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100000 \
--threads 50 \
--duration 300 \
--warmup-duration 30 \
--rollback-percentage 2 \
--branches 3 \
--export-csv results.csv \
--application-id my-benchmark-app \
--tx-service-group my_tx_group
Usage: seata-benchmark [-hV] [--application-id=<applicationId>]
[-d=<duration>] [--export-csv=<exportCsv>]
[-m=<mode>] [-s=<server>] [-t=<targetTps>]
[--saga-shape=<sagaShape>]
[--saga-workload=<sagaWorkload>]
[--saga-fail-step=<sagaFailStep>]
[--saga-random-seed=<sagaRandomSeed>]
[--saga-timeout-step=<sagaTimeoutStep>]
[--saga-timeout-ms=<sagaTimeoutMs>]
[--threads=<threads>] [--tx-service-group=<txServiceGroup>]
[--warmup-duration=<warmupDuration>]
[--rollback-percentage=<rollbackPercentage>]
[--branches=<branches>]
Options:
-s, --server=<server> Seata Server address (host:port)
-m, --mode=<mode> Transaction mode: AT, TCC, SAGA, XA, or SAGA_ANNOTATION
-t, --tps=<targetTps> Target TPS (default: 100)
--threads=<threads> Concurrent threads (default: 10)
-d, --duration=<duration> Duration in seconds (default: 60)
--warmup-duration=<warmupDuration>
Warmup duration in seconds (default: 0)
--rollback-percentage=<rollbackPercentage>
Rollback percentage for fault injection (0-100, default: 2)
--saga-shape=<sagaShape> Select SAGA state machine shape: simple or order.
If omitted, the benchmark keeps the existing
branches-based compatibility behavior.
--saga-workload=<sagaWorkload> Select SAGA workload implementation: mock or db.
The default is mock. The db workload uses
Testcontainers MySQL for DB-backed order,
inventory, and payment actions.
--saga-fail-step=<sagaFailStep> Restrict SAGA failure injection to one forward step:
inventory, payment, or order.
The failure ratio is still controlled by
--rollback-percentage.
--saga-random-seed=<sagaRandomSeed>
Optional random seed for reproducible SAGA
failure injection behavior.
--saga-timeout-step=<sagaTimeoutStep>
Simulate SAGA timeout at one forward step:
inventory, payment, or order.
--saga-timeout-ms=<sagaTimeoutMs>
Simulated timeout delay in milliseconds for
SAGA timeout injection (default: 3000).
--branches=<branches> Number of branch transactions
0 = empty mode (protocol overhead only)
>=1 = real mode (actual execution)
--export-csv=<exportCsv> Export metrics to CSV file
--application-id=<applicationId>
Seata application ID (default: benchmark-app)
--tx-service-group=<txServiceGroup>
Seata tx service group (default: default_tx_group)
-h, --help Show this help message
-V, --version Print version information
The benchmark tool supports YAML configuration files. Configuration priority (highest to lowest):
BENCHMARK_CONFIG_FILEbenchmark.config.filebenchmark.yaml# benchmark.yaml
server: 127.0.0.1:8091
mode: AT
targetTps: 100
threads: 10
duration: 60
warmupDuration: 10
rollbackPercentage: 2
branches: 0
applicationId: benchmark-app
txServiceGroup: default_tx_group
During execution, the tool displays progress every 10 seconds:
Starting benchmark...
[00:10] 1000 txns, 100.2 txns/sec, 99.0% success
[00:20] 2000 txns, 100.1 txns/sec, 99.2% success
[00:30] 3000 txns, 99.8 txns/sec, 99.5% success
...
When the benchmark completes, a final report is displayed:
===================================================
Seata Benchmark Final Report
===================================================
Mode: SAGA
Saga Workload: db
Saga Shape: order
Total Transactions: 6,000
Success Count: 5,780
Failed Count: 220
Success Rate: 96.33%
Committed Count: 4,860
Compensated Count: 920
Execution Failed Count: 180
Compensation Failed Count: 40
Unknown Count: 0
Committed Rate: 81.00%
Compensated Rate: 15.33%
End-State Success Rate: 96.33%
Average TPS: 100.0
Elapsed Time: 60 seconds
Latency Statistics:
P50: 12 ms
P95: 45 ms
P99: 89 ms
P99.9: 120 ms
Max: 230 ms
===================================================
For timeout simulation scenarios, the reported Elapsed Time may slightly exceed the configured --duration because already-started transactions are allowed to finish before the workload generator stops.
For DB-backed SAGA scenarios, the final report and CSV output also include Saga Workload, so benchmark results from mock and db workloads can be compared explicitly.
Use --export-csv to export metrics:
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--duration 60 \
--export-csv results.csv
Output format:
Metric,Value
Mode,SAGA
Saga Workload,db
Saga Shape,order
Total Transactions,6000
Success Count,5780
Failed Count,220
Success Rate (%),96.33
Committed Count,4860
Compensated Count,920
Execution Failed Count,180
Compensation Failed Count,40
Unknown Count,0
Committed Rate (%),81.00
Compensated Rate (%),15.33
End-State Success Rate (%),96.33
Average TPS,100.0
Elapsed Time (s),60
Latency P50 (ms),12
Latency P95 (ms),45
Latency P99 (ms),89
Latency P99.9 (ms),120
Latency Max (ms),230
Export Time,2025-12-01 10:30:45
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--duration 60
# Requires Docker for Testcontainers MySQL
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--duration 60 \
--branches 3
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--duration 60 \
--branches 3 \
--rollback-percentage 5
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--duration 60 \
--branches 3 \
--rollback-percentage 20 \
--saga-fail-step payment
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--duration 60 \
--branches 3 \
--saga-shape order \
--saga-workload db
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 10 \
--threads 1 \
--duration 10 \
--branches 3 \
--saga-shape order \
--saga-workload db \
--rollback-percentage 20 \
--saga-fail-step payment
# Empty mode: protocol overhead only
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA_ANNOTATION \
--tps 100 \
--duration 60
# Real mode: 3 branches per transaction, 5% compensation rate
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA_ANNOTATION \
--tps 100 \
--duration 60 \
--branches 3 \
--rollback-percentage 5
# State-machine Saga
java -jar seata-benchmark-cli.jar --server 127.0.0.1:8091 \
--mode SAGA --tps 10000 --threads 50 --duration 60 --branches 3
# Annotation-based Saga
java -jar seata-benchmark-cli.jar --server 127.0.0.1:8091 \
--mode SAGA_ANNOTATION --tps 10000 --threads 50 --duration 60 --branches 3
# Empty mode: protocol overhead only
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode XA \
--tps 100 \
--threads 1 \
--duration 60
# Real mode: 3 XA branches per transaction
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode XA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3
# Real mode with rollback injection
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode XA \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--rollback-percentage 10
# Empty mode: protocol overhead only (fixed TPS)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode TCC \
--tps 100 \
--threads 1 \
--duration 60
# Empty mode: max throughput (fixed concurrency)
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode TCC \
--tps 100000 \
--threads 50 \
--duration 60
# Real mode: 3 branches per transaction, 10% cancel rate
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode TCC \
--tps 100 \
--threads 1 \
--duration 60 \
--branches 3 \
--rollback-percentage 10
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 200 \
--threads 1 \
--duration 120 \
--warmup-duration 30
| Mode | Empty Mode (branches=0) | Real Mode (branches>0) |
|---|---|---|
| AT | Pure protocol overhead | MySQL via Testcontainers (account transfer) |
| TCC | Pure protocol overhead | Real try/confirm/cancel via @LocalTCC interceptor |
| SAGA | Mock simulation | State machine engine with compensation |
| XA | Pure protocol overhead | MySQL XA via Testcontainers (account transfer) |
| SAGA_ANNOTATION | Pure protocol overhead | Annotation interceptor + TC compensation callback |
For accurate benchmarking of Seata Server capacity, the tool executes empty transactions:
begin() and commit() operations, no SQL executionThis approach:
When --branches is set to a value greater than 0:
AT Mode:
TCC Mode:
@LocalTCC + @TwoPhaseBusinessAction annotation pathtry (prepare) runs in the business thread; commit / rollback are invoked by the TC--branches N = N TCC branch registrations per transactionSAGA Mode:
mock and db workloadsbenchmarkSimpleSaga: For 1-2 branchesbenchmarkOrderSaga: For 3+ branches (order/inventory/payment)XA Mode:
DataSourceProxyXA--branches N XA-backed account transfer branches per global transactionmock workload:
db workload:
SAGA_ANNOTATION Mode:
@SagaTransactional + @CompensationBusinessAction annotation path--branches N = N @CompensationBusinessAction calls per transactionUse --rollback-percentage to simulate transaction failures:
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode SAGA \
--tps 100 \
--duration 60 \
--branches 3 \
--rollback-percentage 10 # 10% of transactions will trigger rollback/compensation
Use --warmup-duration to exclude JVM warmup period from final statistics:
java -jar seata-benchmark-cli.jar \
--server 127.0.0.1:8091 \
--mode AT \
--tps 100 \
--duration 120 \
--warmup-duration 30 # First 30 seconds excluded from final stats
To prevent OOM on large-scale tests, the tool samples latencies (inspired by Kafka ProducerPerformance):
If you see connection errors:
If TPS is lower than expected:
--threads)--branches 0) to isolate Seata overheadIf real mode fails:
Logs are written to seata-benchmark.log in the current directory.
v1.1 - Enhancement:
v2.0 - Advanced Features:
Licensed under the Apache License, Version 2.0