分布式ID性能评测:CosId VS 美团 Leaf
基准测试环境
- MacBook Pro (M1)
- JDK 17
- JMH 1.36
- 运行在本机的Docker 的 mariadb:10.6.4
运行基准测试
CosId
SegmentChainId
模式,基准测试代码:
@Benchmark
public long generate() {
return segmentChainId.generate();
}
Leaf 基准测试代码:
@Benchmark
public long generate() {
Result result = idGen.get(bizTag);
if (Status.SUCCESS.equals(result.getStatus())){
return result.getId();
}
return generate();
}
基准测试代码地址: https://github.com/Ahoo-Wang/CosId/tree/main/cosid-benchmark
git clone git@github.com:Ahoo-Wang/CosId.git
cd cosid-benchmark
./gradlew jmh
基准测试报告
# JMH version: 1.36
# VM version: JDK 17.0.7, OpenJDK 64-Bit Server VM, 17.0.7+7-LTS
# Warmup: 1 iterations, 10 s each
# Measurement: 1 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
Benchmark (step) Mode Cnt Score Error Units
AtomicLongBenchmark.generate N/A thrpt 142725210.565 ops/s
CosIdBenchmark.generate 1 thrpt 131920684.604 ops/s
CosIdBenchmark.generate 100 thrpt 132113994.232 ops/s
CosIdBenchmark.generate 1000 thrpt 130281016.155 ops/s
LeafBenchmark.generate 1 thrpt 25787669.815 ops/s
LeafBenchmark.generate 100 thrpt 23897328.183 ops/s
LeafBenchmark.generate 1000 thrpt 23550106.538 ops/s
GitHub Action 环境测试报告: Performance: CosId vs Leaf
因受到 GitHub Runner 资源限制,运行在 GitHub Runner 中的基准测试与真实环境基准测试对比有非常大的差距(近2倍),
但是对于运行在同一环境配置资源情况下(都运行在 GitHub Runner),进行 commit 前后的基准对比、以及第三方库的对比依然是有价值的。
基准测试结论
- CosId (
SegmentChainId
) 性能是 Leaf (segment
) 的 5 倍。 - CosId 、Leaf 的性能与号段步长(Step) 无关。
- CosId TPS 基本接近
AtomicLong
,参考 https://www.cnblogs.com/Ahoo-Wang/p/cosid-segment-chain.html。
作者:Ahoo Wang (阿虎)
Github: https://github.com/Ahoo-Wang/
SmartSql(高性能、高生产力,超轻量级的ORM!): https://github.com/Ahoo-Wang/SmartSql
SmartCode(不只是代码生成器!): https://github.com/Ahoo-Wang/SmartCode
CoSky 高性能、低成本微服务治理平台 : https://github.com/Ahoo-Wang/CoSky
CosId 通用、灵活、高性能的分布式 ID 生成器 : https://github.com/Ahoo-Wang/CosId
Wow 基于 DDD、EventSourcing 的现代响应式 CQRS 架构微服务开发框架: https://github.com/Ahoo-Wang/Wow
CoSec 基于 RBAC 和策略的多租户响应式安全框架: https://github.com/Ahoo-Wang/CoSec
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。