mongo读写分离的一些坑

在使用mongo副本集的时候就在想,这些副本不用来读太浪费了,再翻阅php的mongodb驱动,发现一个美好的readPreference,可以设定读取的优先级,其中就有优先读取副本,甚至还可以设定读取最小网络延迟的节点,具体可以参考:http://php.net/manual/zh/mongodb-driver-readpreference.construct.php

愿望是美好的,然而使用的过程中当我优先读取secondary时候,经常发现有的读取时间在几秒甚至几十秒的情况,也是醉了。于是经过一番搜索,发现有一个博客提到了这个问题,在官方文档中有说明,原文如下:

How does concurrency affect secondaries?

In replication, MongoDB does not apply writes serially to secondaries. Secondaries collect oplog entries in batches and then apply those batches in parallel. Secondaries do not allow reads while applying the write operations, and apply write operations in the order that they appear in the oplog.

地址是:https://docs.mongodb.com/manual/faq/concurrency/#how-does-concurrency-affect-secondaries

说的是在副本集中,mongodb在同步oplog的时候,副本是不能被读取的。我也是...呵呵哒....

对于频繁写入的mongo,直接读primary吧!

赞赏

微信赞赏支付宝赞赏

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注