MongoDB 不会在副本集中分配读取
我们的副本集中有三台服务器。举例来说,ServerA 是主服务器,而 ServerB 和 ServerC 是辅助服务器。在对环境进行压力测试时,ServerA 上的服务器负载已飙升至 4.00 左右,而辅助服务器仍保持在 0.00。压力测试的 URL 目标不会对 mongo 进行任何写入,但读取似乎不会分发到辅助节点。
我们使用官方 C# 驱动程序。
ServerA 日志显示许多正在打开的连接、lsn 设置条目和一堆“killcursors”命令——它显然正在努力提供页面。然而,ServerB 和 ServerC 仅显示来自 Web 服务器(其中四个)的初始连接,之后日志中仅显示“lsn set”条目。几分钟后,最初的四个连接超时并关闭。
副本集处于完整工作状态。我可以在主要节点上停止 mongo,并且辅助节点将正确选择一个新的主要节点。
来自 Web.config 的连接字符串:
<connectionStrings>
<add name="wellness.mongodb" connectionString="mongodb://serverA:27017,serverB:27017,serverC:27017/mydatabase?safe=true;replicaset=myreplicaset;slaveok=true" />
</connectionStrings>
我们做错了什么?
We have three servers in a replica set. For the sake of example, ServerA is primary, while ServerB and ServerC are secondaries. While stress testing the environment, the server load on ServerA has spiked to around 4.00, while the secondaries remain at 0.00. The URL targets of the stress testing do not do any writes to mongo, but it appears that reads are not being distributed to the secondaries.
We are using the official C# driver.
ServerA log shows many connections being opened, lsn set entries, and a bunch of "killcursors" commands -- it is obviously working to serve up pages. ServerB and ServerC, however, only show the initial connections from the web servers (four of them), and after that only "lsn set" entries appear in the logs. After a few minutes, the initial four connections timeout and close.
The replica set is in full working order. I can stop mongo on the primary, and the secondaries will correctly elect a new primary.
Our connection string from Web.config:
<connectionStrings>
<add name="wellness.mongodb" connectionString="mongodb://serverA:27017,serverB:27017,serverC:27017/mydatabase?safe=true;replicaset=myreplicaset;slaveok=true" />
</connectionStrings>
What are we doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
连接字符串看起来没问题。我会尝试重现并报告。
The connection string looks OK. I'll try and reproduce and report back.