分布式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
相关推荐
唐叔在学习8 分钟前
9类主流数据库 - 帮你更好地进行数据库选型!
数据库·redis·mysql·mongodb·nosql·大数据存储
失因1 小时前
Linux 权限管理与 ACL 访问控制
linux·运维·服务器·数据库·centos
cookqq2 小时前
mongodb源代码分析创建db流程分析
数据库·sql·mongodb·nosql
yh云想2 小时前
存储函数与触发器:数据库自动化与业务逻辑封装的核心技术
数据库·sql
ZZH1120KQ2 小时前
ORACLE复杂查询
数据库·oracle
山茶花开时。2 小时前
[Oracle] TO_DATE()函数
数据库·oracle
小傅哥2 小时前
【分享】拼团交易平台系统,分布式、高并发、微服务
分布式·微服务·状态模式
the beard2 小时前
MySQL进阶:(第八篇)深入解析InnoDB存储架构
数据库·mysql
九河云2 小时前
电商直播流量爆发式增长,华为云分布式流量治理与算力调度服务的应用场景剖析
分布式·科技·华为云·电商·传统
Monika Zhang2 小时前
Redis缓存详解及常见问题解决方案
数据库·redis·缓存