問題描述
複製集同步時發生Mongod慢查詢 (Mongod slow query be happend when replicate set sync)
最近,我發現一個插入操作會使 mongod 慢查詢發生。並且總是在輔助 mongod 實例從另一個節點同步數據時發生。
複製集有三個成員,我將客戶端驅動程序寫入關注點設置為“w:2”。
oplog同步會阻止插入操作?將文檔插入同步節點會發生什麼?
參考解法
方法 1:
The writeConcern setting w:2
means that the write will be acknowledged when exactly two members of the replica set has acknowledged that the write happened (see https://docs.mongodb.com/v3.2/reference/write‑concern/#w‑option). In other words, it will wait until the write has replicated (via the oplog) to one other node, since the Primary is counted as one node.
This means that the "speed" of the insert/update query will be subject to your network speed. If the network is slow or congested, then the insert will appear to be "slow". This is not due to replication blocking anything, it is simply the effect of specifying w:2
in a congested network.
There may be a network congestion that triggers both the sync source change and the slow insert, but the replication process by itself does not block any insert operation.
(by yangbinnnn、kevinadi)