In-place update in WiredTiger

简介:

There is a great new feature in the release note of MongoDB 3.5.12.

Faster In-place Updates in WiredTiger

This work brings improvements to in-place update workloads for users running the WiredTiger engine, especially for updates to large documents. Some workloads may see a reduction of up to 7x in disk utilization (from 24 MB/s to 3 MB/s) as well as a 20% improvement in throughput.

I thought wiredtiger has impeletementd the delta page feature introduced in the bw-tree paper, that is, writing pages that are deltas from previously written pages. But after I read the source code, I found it's a totally diffirent idea, in-place update only impacted the in-meomry and journal format, the on disk layout of data is not changed.

I will explain the core of the in-place update implementation.

MongoDB introduced mutable bson to descirbe document update as incremental(delta) update.

Mutable BSON provides classes to facilitate the manipulation of existing BSON objects or the construction of new BSON objects from scratch in an incremental fashion.

Suppose you have a very large document, see 1MB

{
   _id: ObjectId("59097118be4a61d87415cd15"),
   name: "ZhangYoudong",
   birthday: "xxxx",
   fightvalue: 100,
   xxx: .... // many other fields
}

If the fightvalue is changed from 100 to 101, you can use a DamageEvent to describe the update, it just tells you the offset、size、content(kept in another array) of the change.

struct DamageEvent {
    typedef uint32_t OffsetSizeType;
    // Offset of source data (in some buffer held elsewhere).
    OffsetSizeType sourceOffset;

    // Offset of target data (in some buffer held elsewhere).
    OffsetSizeType targetOffset;

    // Size of the damage region.
    size_t size;
};

So if you have many small changes for a document, you will have DamageEvent array, MongoDB add a new storage interface to support inserting DamageEvent array (DamageVector).

bool WiredTigerRecordStore::updateWithDamagesSupported() const {
    return true;
}

StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages(
    OperationContext* opCtx,
    const RecordId& id,
    const RecordData& oldRec,
    const char* damageSource,
    const mutablebson::DamageVector& damages) {

}

WiredTiger added a new update type called WT_UPDATE_MODIFIED to support MongoDB, when a WT_UPDATE_MODIFIED update happened, wiredTiger first logged a change list which is transformed from DamageVector into journal, then kept the change list in memory associated with the original record.

When the record is read, wiredTiger will first read the original record, then apply every operation in change list, returned the final record to the client.

So the core for in-place update:

  1. WiredTiger support delta update in memory and journal, so the IO of writing journal will be greatly reduced for large document.
  2. WiredTiger's data layout is kept unchanged, so the IO of writing data is not changed.
相关文章
|
前端开发 Ubuntu Linux
【.NET6+Avalonia】开发支持跨平台的仿WPF应用程序以及基于ubuntu系统的演示
随着跨平台越来越流行,.net core支持跨平台至今也有好几年的光景了。但是目前基于.net的跨平台,大多数还是在使用B/S架构的跨平台上;至于C/S架构,大部分人可能会选择QT进行开发,或者很早之前还有一款Mono可以支持.NET开发者进行开发跨平台应用。
2104 0
【.NET6+Avalonia】开发支持跨平台的仿WPF应用程序以及基于ubuntu系统的演示
|
3月前
|
Web App开发 人工智能 编解码
AI 测试提效 | UI 自动化测不出样式 bug?分享 ui-visual-assert + Skill 视觉断言与多浏览器适配方案
本文介绍 `ui-visual-assert` 技能:在 UI 自动化中补全视觉断言,解决 DOM 断言无法发现的样式错乱、布局偏移、响应式断裂、多浏览器渲染差异等问题。AI 自动生成截图比对脚本、响应式视口与跨浏览器配置,支持像素级校验与基线管理,实现“功能+视觉”全维度校验。
407 2
AI 测试提效 | UI 自动化测不出样式 bug?分享 ui-visual-assert + Skill 视觉断言与多浏览器适配方案
|
存储 运维 监控
阿里云物联网平台高级功能之固件升级
OTA(Over-the-Air Technology)即空中下载技术。阿里云物联网平台支持通过OTA方式进行设备固件升级。本文以MQTT协议下的固件升级为例,介绍OTA固件升级流程、数据流转使用的Topic和数据格式。本文使用MQTT.fx客户端模拟设备,进行固件升级流程的操作演示。
3801 0
阿里云物联网平台高级功能之固件升级
|
11月前
|
运维 负载均衡 监控
微服务有哪些优缺点?
微服务将应用拆分为小型独立服务,具备技术异构、弹性好、易部署、可独立扩展等优势,适合复杂系统。但其也带来分布式复杂性、运维难、数据一致性挑战等问题,需权衡团队能力与项目需求后采用。
|
缓存 前端开发 数据可视化
Webpack Bundle Analyzer:深入分析与优化你的包
Webpack Bundle Analyzer是一款可视化工具,帮助分析Webpack构建结果,找出占用空间较大的模块以便优化。首先需安装Webpack和Webpack Bundle Analyzer,接着在`webpack.config.js`中配置插件。运行Webpack后,会在`dist`目录生成`report.html`,展示交互式图表分析包大小分布。为优化可采用代码分割、Tree Shaking、压缩插件、加载器优化、模块懒加载、代码预热、提取公共库、使用CDN、图片优化、利用缓存、避免重复模块、使用Source Maps、优化字体和图标、避免全局样式污染以及优化HTML输出等策略。
1022 3
|
JSON API 开发者
唯品会商品API,开发者示例
唯品会商品API支持获取商品详情、价格及库存信息,适用于开发者集成商品数据。通过如`vip.item_get`等接口,可使用Python等语言调用,实现商品信息查询与列表筛选。实际使用需申请官方授权或通过第三方平台接入,并遵守相关调用规则。
|
机器学习/深度学习 算法 数据可视化
算法金 | 再见!!!K-means
**k-means 算法的简要总结:** - **k-means** 是一种非监督学习的聚类算法,用于将数据分为 k 个类别。 - **工作流程** 包括初始化 k 个中心点,分配数据点到最近的中心,更新中心点,然后迭代直到中心点稳定或达到最大迭代次数。 - **优点** 包括简单易懂、计算效率高,适合大规模数据,结果直观。 - **缺点** 包括需要预设 k 值,对初始中心点敏感,假设簇是凸形,受异常值影响大。
1064 2
算法金 | 再见!!!K-means
|
Web App开发 网络协议 Android开发
Android平台一对一音视频通话方案大比拼:WebRTC VS RTMP VS RTSP,谁才是王者?
【9月更文挑战第4天】本文详细对比了在Android平台上实现一对一音视频通话时常用的WebRTC、RTMP及RTSP三种技术方案。从技术原理、性能表现与开发难度等方面进行了深入分析,并提供了示例代码。WebRTC适合追求低延迟和高质量的场景,但开发成本较高;RTMP和RTSP则在简化开发流程的同时仍能保持较好的传输效果,适用于不同需求的应用场景。
1694 2
在 Vue3 + ElementPlus 项目中使用 el-autocomplete 控件
本文介绍了在Vue3 + ElementPlus项目中如何使用`el-autocomplete`控件实现自动补全输入功能,并探讨了不同版本ElementPlus中`clearable`属性的兼容性问题。
2000 0
在 Vue3 + ElementPlus 项目中使用 el-autocomplete 控件
|
JSON JavaScript 前端开发
技术心得:利用JsonSchema校验json数据内容的合规性
技术心得:利用JsonSchema校验json数据内容的合规性
1493 0