内存中的 MongoDB 索引分片

发布于 2025-01-01 02:43:45 字数 103 浏览 2 评论 0原文

坊间流传的说法是,如果无法将正在使用的索引保留在内存中,MongoDB 就会变慢。这如何与分片一起使用?分片是否只在内存中保留自己的 BTree,还是每个分片都需要在内存中保留整个集合的索引?

The word on the street is that MongoDB gets slow if you can't keep the indexes you're using in memory. How does this work with sharding? Does a sharded only keep its own BTree in memory, or does every shard need to keep the index for the entire collection in memory?

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

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

发布评论

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

评论(2

一页 2025-01-08 02:43:45

分片是否只在内存中保留自己的 BTree...?

是的,每个分片管理自己的索引。

坊间流传的说法是,如果无法将正在使用的索引保留在内存中,MongoDB 就会变慢。

使用分片和二级索引时,实际上可能会出现更糟糕的情况。关键问题是路由器进程 (mongos) 对二级索引中的数据一无所知。

如果您使用分片键进行查询,它将直接路由到正确的服务器。在大多数情况下,这可以平衡工作量。因此,100 个查询可以分布在 100 个服务器上,每个服务器仅回答 1 个查询。

但是,如果您使用辅助键执行查询,则该查询必须发送到每台服务器。因此,对路由器的 100 个查询将导致跨 100 个服务器的 10,000 个查询或每个服务器 100 个查询。随着您添加更多服务器,这些“非分片键”查询的效率会变得越来越低。工作负载没有变得更加平衡。

此处的 MongoDB 文档提供了一些详细信息。

Does a sharded only keep its own BTree in memory...?

Yes, each shard manages its own indexes.

The word on the street is that MongoDB gets slow if you can't keep the indexes you're using in memory.

You can actually expect worse when using sharding and secondary indexes. The key problem is that the router process (mongos) knows nothing about data in secondary indexes.

If you do a query using the shard key, it will be routed directly to the correct server(s). In most cases, this levels out the workload. So 100 queries can be spread across 100 servers and each server only answers 1 query.

However, if you do a query using the secondary key, that query has to go to every server. So 100 queries to the router will result 10,000 queries across 100 servers or 100 queries per server. As you add more servers, these "non-shardkey" queries become less and less efficient. The workload does not become more balanced.

Some details are available in the MongoDB docs here.

埋情葬爱 2025-01-08 02:43:45

只是它自己的索引部分(它不知道其他分片的数据)。否则,缩放不会很好地发挥作用。有关分片的更多信息,请参阅此文档:
http://www.mongodb.org/display/DOCS/Sharding+Introduction

http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key

Just its own portion of the index (it doesn't know about the other shards' data). Scaling wouldn't work very well, otherwise. See this documentation for some more information about sharding:
http://www.mongodb.org/display/DOCS/Sharding+Introduction

http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key

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