MongoDB 副本集中的每台服务器都需要拥有完全相同的 RAM 吗?

发布于 2024-11-07 09:59:12 字数 148 浏览 4 评论 0原文

我可以使用具有不同 RAM 量的服务器在 MongoDB 1.8 中设置副本集吗?

  • server1: 5gb
  • server2: 2gb
  • server3: 4gb

如果是,有何优缺点?

Can I set up a replica set in MongoDB 1.8 using servers with different amounts of RAM?

  • server1: 5gb
  • server2: 2gb
  • server3: 4gb

If yes, what are the pros and cons?

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

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

发布评论

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

评论(2

骷髅 2024-11-14 09:59:12

不,您不需要相同的 RAM。 (是的,您可以按照描述设置副本集。)

MongoDB 使用内存映射文件进行所有缓存,这意味着缓存分页由操作系统处理。具有更多内存的副本将在内存中保留更多的数据库;那些较少的将更多地分页到磁盘。

如果可以的话,MongoDB 最终会将整个数据库放入内存中。如果您使用两个副本进行读取,一个用于写入,您可能需要使用 5GB 和 4GB 计算机进行读取,因此它们更有可能占用 RAM。

No, you do not need equal RAM. (Yes, you could set up a replica set as described.)

MongoDB uses memory-mapped files for all caching, which means that cache paging is handled by the operating system. The replicas with more memory will keep more of the database in memory; those with less will page more to disk.

MongoDB will eventually bring the entire database into memory if it can. If you're using two replicas for reads and one for writes, you might want to use the 5gb and 4gb machines for reads, so they are more likely to be hitting RAM.

有深☉意 2024-11-14 09:59:12

是的,您可以通过这种方式配置副本集。

如果是,有什么优点和缺点?

这里有一个文档解释了副本集的主要功能。让我们根据 RAM 差异来看看这些。

优点:

  • 更多的计算机意味着更好的数据冗余。拥有 2GB 节点至少意味着您多了一份数据副本。
  • 副本集上拥有完整的 3 个节点可以更轻松地删除一个节点进行维护

缺点

  • 拥有不同大小的服务器不利于自动故障转移。假设您的 5GB 服务器是主服务器。当它宕机并且 2GB 服务器赢得选举时会发生什么?您仍然可以进行自动故障转移,但您的性能可能会急剧下降。
  • 读取缩放可能效果不佳。根据您的读取模式,将读取发送到 2GB 服务器可能会导致大量额外的磁盘命中和性能下降。

所以,这里的大问题实际上是性能问题。如果您只是为了开发设置而执行此操作,那么它基本上可以工作。但在生产中,您面临着应用程序完全崩溃的风险。如果您的应用程序习惯于使用 4GB 以上的 RAM,然后突然降至 2GB,则它可能会变得无法使用。

大多数生产设置都希望故障转移到另一台“同等功率”的计算机。

Yes, you can configure a replica set this way.

If yes, what are the pros and cons?

Here's a doc explaining the major features of replica sets. Let's take a look at these in light of the RAM differences.

Pros:

  • More computers means better data redundancy. Having that 2GB node at least means that you have one more copy of the data.
  • Having a full 3 nodes on a replica set makes it easier to take one down for maintenance.

Cons:

  • Having servers of different sizes isn't great for automated failover. Let's say that your 5GB server is the primary. What happens when it goes down and the 2GB server wins the election? You still have automated fail-over, but your performance has probably dropped dramatically.
  • Read scaling may not work very well. Depending on your read patterns, sending reads to the 2GB server may result in lots of extra disk hits and slower performance.

So, the big problem here, is really one of performance. If you're just doing this for a dev setup, then it will basically work. But in production you run the risk of completely tanking your app. If your app is used to living on 4GB+ of RAM and then suddenly drops to 2GB, it may become unusable.

Most production setups want to fail over to another "equally-powered" computer.

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