分布式ID性能评测:CosId VS 美团 Leaf

环境

  • MacBook Pro (M1)
  • JDK 17
  • JMH 1.36
  • 运行在本机 Docker 内的 mariadb:10.6.4

运行

CosId SegmentChainId 模式,基准测试代码:

java 复制代码
    @Benchmark
    public long generate() {
        return segmentChainId.generate();
    }

Leaf 基准测试代码:

java 复制代码
    @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

shell 复制代码
git clone git@github.com:Ahoo-Wang/CosId.git
cd cosid-benchmark
./gradlew jmh

or

shell 复制代码
gradle jmhJar
java -jar build/libs/cosid-benchmark-2.2.6-jmh.jar -wi 1 -rf json -f 1

报告

复制代码
# 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 前后的基准对比、以及第三方库的对比依然是有价值的。

结论

  1. CosId (SegmentChainId) 性能是 Leaf (segment) 的 5 倍。
  2. CosId 、Leaf 的性能与号段步长(Step) 无关。
  3. CosId TPS 基本接近 AtomicLong
相关推荐
ohoy1 小时前
mysql 30天自动补0
数据库·mysql
没有bug.的程序员2 小时前
单体 → 微服务演进路径:一个真实电商项目的渐进式转型
jvm·微服务·云原生·架构·电商·gc调优
摇滚侠3 小时前
Redis 零基础到进阶,Redis 哨兵监控,笔记63-73
数据库·redis·笔记
利剑 -~3 小时前
mysql面试题整理
android·数据库·mysql
老华带你飞3 小时前
物流信息管理|基于springboot 物流信息管理系统(源码+数据库+文档)
数据库·vue.js·spring boot
程序员卷卷狗4 小时前
Redis事务与MySQL事务有什么区别?一文分清
数据库·redis·mysql
玩大数据的龙威4 小时前
农经权二轮延包—数据(新老农经权)比对软件更新
数据库·arcgis
保持低旋律节奏4 小时前
网络系统管理——期末复习
数据库
程序员佳佳5 小时前
2025年大模型终极横评:GPT-5.2、Banana Pro与DeepSeek V3.2实战硬核比拼(附统一接入方案)
服务器·数据库·人工智能·python·gpt·api
roo_15 小时前
github 获取构造图数据库的LNB数据集和使用说明
数据库