# 协议解码性能五倍提升！写入性能持续优化 | Greptime 双周精选

Source: https://greptime.cn/blogs/2024-03-13-biweekly

## 内容概述

作为一个成长中的开源项目，GreptimeDB 的进展离不开来自全球的社区贡献者们，感谢各位！

最近的内容更新如下：

- 写入路径正在持续优化中
- 手动解码 Prometheus Remote Write 协议带来约五倍性能提升
- 新分区规则和 Memtable 现已可用

## 社区贡献者名单

在过去的两周里，GreptimeDB 共合并了 65 个 PR，其中有 5 位独立贡献者，累计 6 个 PR 被成功合并，还有很多待合并的 PR。

祝贺以下各位在过去 2 周内成为我们活跃的贡献者：

- @[crwen](https://github.com/crwen) （[db#3473](https://github.com/GreptimeTeam/greptimedb/pull/3473))

- @[etolbakov](https://github.com/etolbakov) ([db#3445](https://github.com/GreptimeTeam/greptimedb/pull/3445) [db#3390](https://github.com/GreptimeTeam/greptimedb/pull/3390))

- @[gcmutator](https://github.com/gcmutator) ([db#3469](https://github.com/GreptimeTeam/greptimedb/pull/3469))

- @[J0HN50N133](https://github.com/J0HN50N133)（[db#3379](https://github.com/GreptimeTeam/greptimedb/pull/3379))

- @[KKould](https://github.com/KKould)（[db#3372](https://github.com/GreptimeTeam/greptimedb/pull/3372))

🎉 热烈欢迎 @[crwen](https://github.com/crwen) @[gcmutator](https://github.com/gcmutator) @[J0HN50N133](https://github.com/J0HN50N133) 作为新的贡献者加入社区并成功合并了首个 PR，还有更多来自其他独立贡献者的 PR 正在等待合并。

<img src="/zh/blogs/2024-03-13-biweekly/image1.png" alt="Contributor of GreptimeDB" style="width: 80%; margin: 0 auto"/>

同时衷心感谢我们所有的成员和贡献者！是你们的付出让我们的项目得以成功，也是你们让 GreptimeDB 成为一个更优质的产品。让我们一起努力，建立一个更棒的社区！

## PR 亮点

### 写入链路持续优化中

具体实现包括在以下 PR 中：[db#3407](https://github.com/GreptimeTeam/greptimedb/pull/3407) 和 [db#3422](https://github.com/GreptimeTeam/greptimedb/pull/3422) 减少了数据复制的次数；[db#3397](https://github.com/GreptimeTeam/greptimedb/pull/3397), [db#3404](https://github.com/GreptimeTeam/greptimedb/pull/3404), [db#3426](https://github.com/GreptimeTeam/greptimedb/pull/3426), 和[db#3383](https://github.com/GreptimeTeam/greptimedb/pull/3383) 丰富了各种细节流程的 Metrics；[db#3415](https://github.com/GreptimeTeam/greptimedb/pull/3415) 和 [db#3400](https://github.com/GreptimeTeam/greptimedb/pull/3400) 则减小了在内存中处理主键的开销。

### [db#3425](https://github.com/GreptimeTeam/greptimedb/pull/3425) [db#3478](https://github.com/GreptimeTeam/greptimedb/pull/3478) 大幅优化 Prometheus Remote Write 格式的解析开销 

在压测过程中我们发现协议解析部分花费了大量的 CPU，相同的结构在 Go 中解析仅需八分之一的开销。通过深入排查和对比，发现我们所依赖的协议库 prost 存在性能瓶颈，于是针对 Prometheus Remote Write 的协议手动编写了解析的代码，带来了约 5 倍的性能提升。

### [db#3418](https://github.com/GreptimeTeam/greptimedb/pull/3418) 优化重启时的内存占用 

在之前的版本中，我们观察到系统在重启的时候内存会有一个峰值上升，在 GreptimeDB v0.7 中这个问题已经解决。

### [db#3350](https://github.com/GreptimeTeam/greptimedb/pull/3350) 新分区方式和分区语法 

考虑到未来自动分区、重新分区等需要频繁变更分区的需求，我们开始开发一种新的分区语法。目前 RFC 已经合并，开发过程可以通过 [#3351](https://github.com/GreptimeTeam/greptimedb/pull/3351) 来跟踪。

### [db#3430](https://github.com/GreptimeTeam/greptimedb/pull/3430) 新 Memtable 实现已加入默认套餐 

针对大量时间线场景优化的新 Memtable 实现已完全合并并默认启用，测试场景中内存开销可降低 50%，欢迎大家试用。

### [db#3485](https://github.com/GreptimeTeam/greptimedb/pull/3485) 模糊测试持续完善中 

之前开发的模糊测试套件目前持续迭代中，现已发现并修复若干个边界情况，覆盖场景逐步增多。

## Good First Issue

### [db##3492 实现 Prometheus HTTP API](https://github.com/GreptimeTeam/greptimedb/issues/3492) 

以 Grafana 无痛集成为目标，提高 GreptimeDB 在 Prometheus HTTP API 方面的兼容性。

关键词：observability

难度：未定（详情建议 repo 了解）

### [db#3435 为 Prometheus Remote Write 接口提供严格模式的字符串校验](https://github.com/GreptimeTeam/greptimedb/issues/3435)

虽然大部分实现和库都保证输入的 String 类型是 UTF-8 编码的，但还是存在恶意攻击的可能，需要为相关协议实现严格模式的校验来防止这种情况。

关键词：security、protocol

难度：中等

## 关于 Greptime

[Greptime 格睿科技](https://greptime.cn/)专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务，帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 [GreptimeDB](https://github.com/GreptimeTeam/greptimedb) 已经衍生出多款适合不同用户的解决方案，更多信息或 demo 展示请联系下方小助手（微信号：greptime）。

欢迎对开源感兴趣的朋友们参与贡献和讨论，从带有 good first issue 标签的 issue 开始你的开源之旅吧～期待在开源社群里遇见你！添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~

Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb

官网：https://greptime.cn/

文档：https://docs.greptime.cn/

Twitter: https://twitter.com/Greptime

Slack: https://greptime.com/slack

LinkedIn: https://www.linkedin.com/company/greptime/
