[关闭]
@JunQiu 2018-10-03T14:21:05.000000Z 字数 3266 阅读 2104

mongodb并发控制(锁)浅谈(3.0)、mongodb3.0新特性一览、MMAPv1空间占用问题

mongodb summary_2018/09


1、mongodb锁浅谈

1.1、概述

1.2、What type of locking does MongoDB use?

  1. ## mongo中锁的描述
  2. Lock Mode Description
  3. R Represents Shared (S) lock.
  4. W Represents Exclusive (X) lock.
  5. r Represents Intent Shared (IS) lock.
  6. w Represents Intent Exclusive (IX) lock.
  1. ## 当一个X锁刚好释放:队列中:IS → IS → X → X → S → IS
  2. mongo并非严格的FIFOMongoDB will actually grant all IS and S modes,当释放SIS锁时,队列中:IS IS X X
  3. 此时,消费X锁,所以并不会产生饥饿。

1.3、How granular are locks in MongoDB?

1.4、What locks are taken by some common client operations?

  1. ## 对于支持文档级别锁的存储引擎而言:
  2. v3.0:
  3. Operation Database Collection
  4. Issue a query r (Intent Shared) r (Intent Shared)
  5. Insert data w (Intent Exclusive) w (Intent Exclusive)
  6. Remove data w (Intent Exclusive) w (Intent Exclusive)
  7. Update data w (Intent Exclusive)w (Intent Exclusive)
  8. Perform Aggregation r (Intent Shared) r (Intent Shared)
  9. Create an index (Foreground) W (Exclusive)
  10. Create an index (Background) w (Intent Exclusive) w (Intent Exclusive)
  11. Changed in version 4.0:
  12. Map-reduce W (Exclusive) and R (Shared) w (Intent Exclusive) and r (Intent Shared)

1.5、How do I see the status of locks on my mongod instances?

  1. db.serverStatus()
  2. db.currentOp()
  3. mongotop
  4. mongostat
  5. Tips:To terminate an operation, use db.killOp().

1.6、参考文档

2、mongodb3.0新特性一览

2.1、概述

2.2、主要新特性

  1. 1、优化explan函数
  2. 新版本explain函数可以支持countfindgroupaggregateupdateremove等操作的查询计划显示,结果更全面更精细。
  3. 2、重写mongodb工具
  4. 新版本所有mongodb自带工具均使用Go语言重写,特别是在mongodumpmongorestore添加了并行机制,这样可以大大加快数据的导出和导入。
  5. 3、日志输出控制
  6. 新版本中将日志分为不同的模块,其中包括ACCESSCOMMANDCONTROLGEOINDEXNETWORKQUERYREPLSHARDINGSTORAGEJOURNALWRITE等。用户可以动态调整每个模块的日志级别,这无疑更有利于系统问题诊断。
  7. 4 索引构建优化
  8. 后台索引建立过程中,不能进行删库删表删索引操作,且后台索引建立过程不会因此自动中断。另外,使用createIndexes命令可以同时建立多个索引,并且只扫描一遍数据,提升了建索引的效率。
  1. MMAPv1空间占用大的原因:
  2. 1、预分配方式,会占用比较大一部分空间
  3. 2、不支持压缩
  4. 3、存储方式在数据库级别分配:即使删掉了某个集合或者索引,占用的磁盘空间也很难及时自动回收

2.3、参考文档

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注