MongoDB性能 - 具有多个数据库 [英] MongoDB performance - having multiple databases

查看:159
本文介绍了MongoDB性能 - 具有多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序在db中需要5个集合。当我们将客户端添加到我们的应用程序中时,我们希望为每个客户维护单独的db。例如,如果我们有500个客户,我们将有500 dbs和2500个集合(每个db有5个集合)。这样我们可以分离每个客户数据。 更新: https://groups.google.com/forum/?fromgroups#!starred/mongodb-user/UBkJKoeM6Tw =noreferrer> google-group discussion 。



解决方案


我们的应用程序需要在db中有5个集合。当我们将客户端添加到
应用程序中时,我们希望为每个
客户维护单独的db。例如,如果我们有500个客户,我们将有500 dbs
和2500个集合(每个db有5个集合)。这样我们可以用
分隔每个客户数据。


这是一个好主意。除了逻辑分离之外,您还可以使用MongoDB中的数据库级安全性来防止无意中访问其他客户的数据。


我担心的是,是否会导致任何性能问题?


对于一个客户(如果这在您的场景中是可能的),数据库级锁定极其严重的锁争用将不会影响另一个客户的性能(如果他们竞争相同的I / O带宽,但如果您使用--directoryperdb选项您可以将这些数据块放置在单独的物理设备上。



分片还可以轻松扩展,因为您甚至不必分区任何集合 - - 在多个shard之间使用-robin数据库,以允许将负载分配到单独的集群(如果和达到该级别)。



与其他答案中的声明相反, TTLMonitor线程不会将文档拉入RAM,除非它们被删除(并添加到空闲列表中)。



我强烈建议对一个数据库使用多个集合解决方案,因为它不允许您分区负载,也不提供安全性,也不是更容易处理在应用程序端。


Our application needs 5 collections in a db. When we add clients to our application we would like to maintain separate db for each customer. For example, if we have 500 customers, we would have 500 dbs and 2500 collections (each db has 5 collection). This way we can separate each customer data. My concern is, will it lead to any performance problems?

UPDATE: Also follow this google-group discussion.

解决方案

Our application needs 5 collections in a db. When we add clients to our application we would like to maintain separate db for each customer. For example, if we have 500 customers, we would have 500 dbs and 2500 collections (each db has 5 collection). This way we can separate each customer data.

That's a great idea. On top of logical separation this will provide for you, you will also be able to use database level security in MongoDB to help prevent inadvertent access to other customers' data.

My concern is, will it lead to any performance problems?

No, and in fact it will help as with database level lock extremely heavy lock contention for one customer (if that's possible in your scenario) would not affect performance for another customer (it still might if they are competing for the same I/O bandwidth but if you use --directoryperdb option then you have the ability to place those DBs on separate physical devices.

Sharding will also allow easy scaling as you won't even have to partition any collections - you can just round-robin databases across multiple shards to allow the load to be distributed to separate clusters (if and when you reach that level).

Contrary to the claim in the other answer, TTLMonitor thread does NOT pull documents into RAM unless they are being deleted (and added to the free list). They work off of TTL indexes both to tell if any documents are to be expired as well as to located the document directly.

I would strongly recommend against the one database many collections solution as that doesn't allow you to either partition the load, nor provide security, nor is it any easier to handle on the application side.

这篇关于MongoDB性能 - 具有多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆