当通过 mongos 时,如何将 MongoDB 中的读取路由到特定的辅助节点?

发布于 2024-12-10 01:54:57 字数 226 浏览 1 评论 0原文

这是 MongoDB (2.0.0) 的分片设置,具有多个副本集,每个副本集有 3 个节点。 Mongoid 正在通过 mongos。我想将(每个副本集的)辅助节点之一专门用于长时间运行的查询,否则会影响用户体验;我不希望正常的查询去那里。我看到我可以标记节点(数据中心感知),但是如何将读取发送到专门标记的节点?

另一个用例是在不同的数据中心有一个备份节点,但查询应该只发送到本地数据中心,而不是随机分布到远程数据中心。

This is a sharded setup of MongoDB (2.0.0) with multiple replica sets of 3 nodes each. Mongoid is going through mongos. I want to dedicate one of the secondary nodes (of each replica set) for long running queries that would otherwise affect user experience; I don't want normal queries to go there. I see that I can tag the nodes (data center awareness) but how can I send reads to specifically tagged nodes?

The other use case for this would be to have a backup node in a different data center but queries should only go to local data center and not be randomly distributed to include a remote data center.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-12-17 01:54:57

查阅文档后,我很确定不可能做你想做的事,至少在数据库级别是不可能的。由于 mongos 从应用程序中抽象出分片,因此您无法将查询定向到特定分片。

然而,我认为这里有一个更高层次的概念。如果您有一个不需要阻塞 UI 的长时间运行的查询,您最好设置一个消息队列并将查询弹出到其中。这样,查询就可以在后台运行。如果所述查询通常会影响系统的性能,您可能需要通过将其拆分为适用于较小数据集的查询并在内存中重新组装该数据集或找到降低其优先级的方法来降低其影响系统资源不会受到太大影响。

希望这有帮助。

After consulting the docs, I'm pretty sure that it's not possible to do what you want, at least not at the database level. Since mongos abstracts shards from the application, there's no way for you to direct a query to a specific shard.

However, I think that there's a higher level concept here. If you have a long-running query that doesn't need to block the UI, you'd be better off setting up a message queue and pop the query onto it. This way, the query can be run in the background. If said query will affect the performance of the system in general, you probably need to lower the impact of it by either splitting it up into queries that work on a smaller dataset and reassembling this dataset in memory or finding a way to lower its priority so that the system resources aren't too affected.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文