当负载增加时,MongoDB似乎在打电话

发布于 2025-02-08 14:08:09 字数 654 浏览 3 评论 0原文

我们有一个带有1个主要和2次要的Mongo DB复制设置配置。我们已经将读取偏好设置为primary,因为我们的次要之一是在远程区域中,并且不希望读取操作继续进行该节点。

如果我运行collection.find()方法(使用Mongocursor并在响应中进行迭代),在调试模式下一一逐一,我会看到所有调用都将呼叫。

可以通过两种方式验证以上内容:

  1. Mongo驱动程序登录客户端显示命令已发送到主Mongo Server
  2. the Mongodb.log在服务器上打印查找操作(启用slowsms选项)

,但是如果我在没有调试模式的情况下运行相同(更高的速度 +负载),则两个服务器的mongodb.log开始显示查找操作。这是出乎意料的,因为我们希望呼叫只能访问初级而不是远程辅助。另外,mongo驱动程序登录客户端显示命令仅发送到主mongo服务器。

同样,主要和次级mongodb.log的差异在于,读取的读取被显示在次级mongodb.log中的“次级换”(并且我们在代码中的任何位置都不设置此优先级)。

在次级mongodb.log中查看日志的原因是什么

?还是主服务器确实通过secondaryPreferred读取偏好转发了次要的呼叫?

We have a mongo db replica set configuration with 1 primary and 2 secondaries. We have set the read preference to primary because one of our secondary is in a remote region and do not want read operations to go on that node.

If I run the collection.find() method (which is using MongoCursor and iterates through the response), one by one in debug mode, I see all the calls going to primary.

The above can be verified with 2 ways:

  1. mongo driver log on the client shows the command is sent to the primary mongo server
  2. the mongodb.log on the server prints the find operation (enabling slowms option)

However, if I run the same without debug mode (higher speed + load), the mongodb.log for both servers start showing the find operation. This is unexpected as we want the calls to only go to primary and not to the remote secondary. Also, the mongo driver log on the client shows command is send only to the primary mongo server.

Also, the difference in the primary and secondary mongodb.log is that the readPreference is shown "secondaryPreferred" in the secondary mongodb.log (and we do not set this preference anywhere in the code).

What could be the reason for seeing the logs in the secondary mongodb.log ?

Is it just log printing and the calls are really going to primary ? Or the primary server is really forwarding the calls to secondary with secondaryPreferred read preference ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文