分布式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 [email protected]: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
相关推荐
四四夕夕39 分钟前
【保姆级图文】1panel 面板部署雷池社区版:从环境搭建到安全验证全流程实录
数据库·安全
仍然探索未知中1 小时前
MySQL数据库介绍以及安装(本地windows、Ubuntu 20.04)
数据库·mysql
m0_653031362 小时前
腾讯云TCCA认证考试报名 - TDSQL数据库交付运维工程师(PostgreSQL版)
运维·数据库·腾讯云
朱小勇本勇2 小时前
Clang Code Model: Error: The clangbackend executable “D:\Soft\Qt5.12.12\Tool
运维·服务器·数据库·qt·nginx
代码的余温2 小时前
B树与B+树:数据库索引背后的秘密
数据结构·数据库·b树
noravinsc2 小时前
django filter 筛选 取出全部用户id
数据库·mysql
不恋水的雨3 小时前
解决sql查询中in查询项过多时很慢的问题
数据库·sql·mysql
betazhou3 小时前
Oracle goldengate参数:TRANLOGOPTIONS DBLOGREADER
数据库·oracle·dblogreader
云心雨禅3 小时前
Spring Boot热更新技巧:节省90%重启时间
java·数据库·spring boot
码上库利南3 小时前
详细讲解Redis为什么被设计成单线程
数据库·redis·缓存