Mongodb读锁 [英] Mongodb read locks

查看:78
本文介绍了Mongodb读锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含自定义_id和500M +文档的mongodb集合. _id索引的大小为≈25Gb,整个集合的值为≈125Gb.服务器具有96 Gb RAM.读取活动仅是通过_id进行范围查询. Explain()显示查询使用索引.在负载测试开始后的某些时间里,Mongo的工作速度相当快,过一会儿它就会变慢.我在日志中可以看到很多这样的条目:

I have a mongodb collection with custom _id and 500M+ documents. Size of the _id's index is ≈25Gb and whole collection is ≈125 Gb. Server has 96 Gb RAM. Read activity is only range queries by _id. Explain() shows that queries use the index. Mongo works rather fast some time after load tests start and slows down after a while. I can see in a log a lot of entries like this:

[conn116] getmore csdb.archive查询:{_id:{$ gt:2812719756651008,$ lt:2812720361451008}} cursorid:444942282445272280 ntoreturn:0 keyUpdates:0 numYields:748 locks(micros)r :7885031 返回:40302 reslen:1047872 10329ms

[conn116] getmore csdb.archive query: { _id: { $gt: 2812719756651008, $lt: 2812720361451008 } } cursorid:444942282445272280 ntoreturn:0 keyUpdates:0 numYields: 748 locks(micros) r:7885031 nreturned:40302 reslen:1047872 10329ms

一块db.currentOp():

A piece of db.currentOp():

"waitingForLock" : false,
                        "numYields" : 193,
                        "lockStats" : {
                                "timeLockedMicros" : {
                                        "r" : NumberLong(869051),
                                        "w" : NumberLong(0)
                                },
                                "timeAcquiringMicros" : {
                                        "r" : NumberLong(1369404),
                                        "w" : NumberLong(0)
                                }
                        }

什么是locks(micros)r?我该怎么做才能减少它?

What is locks(micros) r? What can I do to cut it down?

推荐答案

什么是locks(micros) r?

读取锁定被保留的时间(以微秒为单位).

  • R-全局读取锁定
  • W-全局写锁定
  • r-特定于数据库的读取锁
  • w-特定于数据库的写锁
  • R - Global read lock
  • W - Global write lock
  • r - Database specific read lock
  • w - Database specific write lock

我该怎么做才能减少它?

What can I do to cut it down?

  • 分片如何影响并发性?

    共享可以通过将集合分布在多个mongod实例上来提高并发性,从而允许分片服务器(即mongos进程)同时对各个下游mongod实例执行任意数量的操作.

    Sharding improves concurrency by distributing collections over multiple mongod instances, allowing shard servers (i.e. mongos processes) to perform any number of operations concurrently to the various downstream mongod instances.

  • 诊断性能问题(锁定)

    MongoDB使用锁定系统来确保数据集的一致性.但是,如果某些操作长时间运行或形成队列,则性能会因请求和操作等待锁定而变慢.与锁定有关的减速可能是间歇性的.要查看锁定是否已影响您的性能,请查看serverStatus输出的globalLock部分中的数据.如果globalLock.currentQueue.total始终很高,则可能有大量请求正在等待锁定.这表明可能存在并发问题,可能会影响性能.

    MongoDB uses a locking system to ensure data set consistency. However, if certain operations are long-running, or a queue forms, performance will slow as requests and operations wait for the lock. Lock-related slowdowns can be intermittent. To see if the lock has been affecting your performance, look to the data in the globalLock section of the serverStatus output. If globalLock.currentQueue.total is consistently high, then there is a chance that a large number of requests are waiting for a lock. This indicates a possible concurrency issue that may be affecting performance.

    如果globalLock.totalTime相对于正常运行时间而言较高,则表明数据库已处于锁定状态已有相当长的时间.如果globalLock.ratio也很高,则MongoDB可能正在处理大量长时间运行的查询.长时间查询通常是由多种因素导致的:索引使用效率低下,方案设计不理想,查询结构不良,系统架构问题或RAM不足导致页面错误和磁盘读取.

    If globalLock.totalTime is high relative to uptime, the database has existed in a lock state for a significant amount of time. If globalLock.ratio is also high, MongoDB has likely been processing a large number of long running queries. Long queries are often the result of a number of factors: ineffective use of indexes, non-optimal schema design, poor query structure, system architecture issues, or insufficient RAM resulting in page faults and disk reads.

  • 我们如何扩展MongoDB (垂直)

  • How We Scale MongoDB (Vertically)

    可悲的是,在服务器容量耗尽之前,MongoDB本身通常会成为瓶颈.写入锁定几乎始终是最大的问题(尽管单个MongoDB进程可以利用多少IO容量存在实际限制).

    Sadly, MongoDB itself will usually become a bottleneck before the capacity of a server is exhausted. Write lock is almost always the biggest problem (though there are practical limits to how much IO capacity a single MongoDB process can take advantage of).

  • 这篇关于Mongodb读锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆