并发机制
以下列出各版本的新特性
MongoDB 2.2 并发机制
https://docs.mongodb.com/v2.2/faq/concurrency/
1、锁类型
使用 readers-writer 锁机制,允许同时有多个读操作,但只能有一个写操作;一个写操作会阻塞其它读、写操作;写操作优先级高于读操作
2、锁粒度
2.2 版本之前只有一个实例级别的全局锁。从 2.2 版本开始大多操作实现了数据库级别的锁粒度,少量操作仍用到实例级的全局锁
3、查看锁状态
i. db.serverStatus()
Locks:https://docs.mongodb.com/v2.2/reference/server-status/#server-status-locks
"locks" : {
"." : {
"timeLockedMicros" : {
"R" : <num>,
"W" : <num>
},
"timeAcquiringMicros" : {
"R" : <num>,
"W" : <num>
}
},
...
"<database>" : {
"timeLockedMicros" : {
"r" : <num>,
"w" : <num>
},
"timeAcquiringMicros" : {
"r" : <num>,
"w" : <num>
}
}
},
Global Lock:https://docs.mongodb.com/v2.2/reference/server-status/#server-status-global-lock
"globalLock" : {
"totalTime" : <num>,
"lockTime" : <num>,
"currentQueue" : {
"total" : <num>,
"readers" : <num>,
"writers" : <num>
},
"activeClients" : {
"total" : <num>,
"readers" : <num>,
"writers" : <num>
}
},
ii. db.currentOp()
Current Operation:https://docs.mongodb.com/v2.2/reference/current-op/
{
"inprog": [
{
"opid" : 3434473,
"active" : <boolean>,
"secs_running" : 0,
"op" : "<operation>",
"ns" : "<database>.<collection>",
"query" : {
},
"client" : "<host>:<outgoing>",
"desc" : "conn57683",
"threadId" : "0x7f04a637b700",
"connectionId" : 57683,
"locks" : {
"^" : "w",
"^local" : "W",
"^<database>" : "W"
},
"waitingForLock" : false,
"msg": "<string>"
"numYields" : 0,
"progress" : {
"done" : <number>,
"total" : <number>
}
"lockStats" : {
"timeLockedMicros" : {
"R" : NumberLong(),
"W" : NumberLong(),
"r" : NumberLong(),
"w" : NumberLong()
},
"timeAcquiringMicros" : {
"R" : NumberLong(),
"W" : NumberLong(),
"r" : NumberLong(),
"w" : NumberLong()
}
}
},
]
}
iii. mongotop
–locks 参数: