Skip to content

Conversation

@sunxien
Copy link
Contributor

@sunxien sunxien commented Jun 14, 2025

refactor(canal/server): 优化程序代码

  • canal server logback.xml 配置增加
    CanalServerWithEmbedded 单独日志配置,流量非常大的情况下,getMessages/ack等日志量非常大
    日志刷盘太快也影响性能,占磁盘空间。用户可以根据需要单独调整日志级别。默认是INFO

  • TableMetaCache 锁的范围太大,针对这块做了代码逻辑优化。以下场景影响性能:

    • 当用户关闭tsdb.enable=false, 分库分表数量非常多回查次数很多;
    • 每张表有四五百列甚至更多,里面的集合容器提前初始化,减少扩容的次数;
  • DatabaseTableMeta 标记一个内存不安全的地方,以后看情况优化掉
    使用MemoryTableMeta在内存区记录表元数据,当分库分表数量非常多,表结构非常复杂非常吃内存,容易OOM

sunxien added 5 commits May 20, 2025 00:08
- adapter 默认提供prometheus暴露JVM指标

- 指定 maven-antrun-plugin 未指定版本号,默认是 3.0.0,但是配置中使用 <tasks> 标签,编译报错。
   - 降级版本号,显式指定 1.8 版本
   - 或者把配置中的 <tasks> 标签改成 <target>
- 提升30%以上的性能
- 顺便解决protobuf历来版本的安全漏洞
- FastJSON2 内存保护机制,默认64MB,超过则抛出OutOfMemory异常
    - 见:JSONWriter.ensureCapacity
- String.format is lower than StringBuilder. Benchmark like below:

code snippet:

String str = String.format("%s-%s-%s", 0, 1, 10);

Benchmark                         Mode     Cnt         Score    Error  Units
StringBenchmark.append           thrpt          46431458.255           ops/s
StringBenchmark.format           thrpt            985724.313           ops/s
StringBenchmark.append            avgt                ≈ 10⁻⁸            s/op
StringBenchmark.format            avgt                ≈ 10⁻⁶            s/op
StringBenchmark.append          sample  364232        ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.00    sample                ≈ 10⁻⁸            s/op
StringBenchmark.append:p0.50    sample                ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.90    sample                ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.95    sample                ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.99    sample                ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.999   sample                ≈ 10⁻⁷            s/op
StringBenchmark.append:p0.9999  sample                ≈ 10⁻⁵            s/op
StringBenchmark.append:p1.00    sample                 0.001            s/op
StringBenchmark.format          sample  336220        ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.00    sample                ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.50    sample                ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.90    sample                ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.95    sample                ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.99    sample                ≈ 10⁻⁶            s/op
StringBenchmark.format:p0.999   sample                ≈ 10⁻⁵            s/op
StringBenchmark.format:p0.9999  sample                ≈ 10⁻⁴            s/op
StringBenchmark.format:p1.00    sample                 0.001            s/op
StringBenchmark.append              ss                ≈ 10⁻⁶            s/op
StringBenchmark.format              ss                ≈ 10⁻⁵            s/op
- canal server logback.xml 配置增加
   CanalServerWithEmbedded 单独日志配置,流量非常大的情况下,getMessages/ack等日志量非常大
   日志刷盘太快也影响性能,占磁盘空间。用户可以根据需要单独调整日志级别。默认是INFO

- TableMetaCache 锁的范围太大,针对这块做了代码逻辑优化。以下场景影响性能:
   - 当用户关闭tsdb.enable=false, 分库分表数量非常多回查次数很多;
   - 每张表有四五百列甚至更多,里面的集合容器提前初始化,减少扩容的次数;

- DatabaseTableMeta 标记一个内存不安全的地方,以后看情况优化掉
	使用MemoryTableMeta在内存区记录表元数据,当分库分表数量非常多,表结构非常复杂非常吃内存,容易OOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant