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.
相关文章
|
NoSQL MongoDB
MongoDB compact 命令详解
为什么需要 compact 一图胜千言 remove 与 drop 的区别 MongoDB 里删除一个集合里所有文档,有两种方式 db.collection.remove({}, {multi: true}),逐个文档从 btree 里删除,最后所有文档被删除,但文件物理空间不会被回收 db.
|
存储 运维 监控
阿里云物联网平台高级功能之固件升级
OTA(Over-the-Air Technology)即空中下载技术。阿里云物联网平台支持通过OTA方式进行设备固件升级。本文以MQTT协议下的固件升级为例,介绍OTA固件升级流程、数据流转使用的Topic和数据格式。本文使用MQTT.fx客户端模拟设备,进行固件升级流程的操作演示。
3776 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输出等策略。
1001 3
|
运维 Dubbo Java
Serverless与微服务(下)
微服务架构,主要是中间层分解,将系统拆分成很多小应用(微服务),微服务可以部署在不同的服务器上,也可以部署在相同的服务器不同的容器上。当应用的故障不会影响到其他应用,单应用的负载也不会影响到其他应用,其代表框架有Spring cloud、Dubbo等。
979 0
Serverless与微服务(下)
|
机器学习/深度学习 算法 数据可视化
算法金 | 再见!!!K-means
**k-means 算法的简要总结:** - **k-means** 是一种非监督学习的聚类算法,用于将数据分为 k 个类别。 - **工作流程** 包括初始化 k 个中心点,分配数据点到最近的中心,更新中心点,然后迭代直到中心点稳定或达到最大迭代次数。 - **优点** 包括简单易懂、计算效率高,适合大规模数据,结果直观。 - **缺点** 包括需要预设 k 值,对初始中心点敏感,假设簇是凸形,受异常值影响大。
1033 2
算法金 | 再见!!!K-means
在 Vue3 + ElementPlus 项目中使用 el-autocomplete 控件
本文介绍了在Vue3 + ElementPlus项目中如何使用`el-autocomplete`控件实现自动补全输入功能,并探讨了不同版本ElementPlus中`clearable`属性的兼容性问题。
1965 0
在 Vue3 + ElementPlus 项目中使用 el-autocomplete 控件
|
存储 NoSQL 数据库
MongoDB Sharded cluster架构原理
为什么需要Sharded cluster? MongoDB目前3大核心优势:『灵活模式』+ 『高可用性』 + 『可扩展性』,通过json文档来实现灵活模式,通过复制集来保证高可用,通过Sharded cluster来保证可扩展性。 当MongoDB复制集遇到下面的业务场景时,你就需要考虑使用Sh
43736 155
|
JSON JavaScript 前端开发
技术心得:利用JsonSchema校验json数据内容的合规性
技术心得:利用JsonSchema校验json数据内容的合规性
1465 0
|
存储 缓存 运维
基础篇丨链路追踪(Tracing)其实很简单
基础篇丨链路追踪(Tracing)其实很简单
基础篇丨链路追踪(Tracing)其实很简单