数据结构不断增长的MongoDB性能

问题描述:

假设我们正在设计一个新系统,并决定使用MongoDB作为主要数据库.数据模式与带有[增长中]评论的博客非常相似.

Let's say we are designing a new system and have decided to use MongoDB as the primary database. The data schema is very similar to a blog with [growing] comments.

在"MongoDB Developers"一书中,技巧6:不要嵌入增长不受限的字段,它表示将数据不断追加到数组的末尾效率低下(但也暗示注释是很奇怪的"边缘情况").

In the book "MongoDB Developers", Tip #6: Do not embed fields that have unbound growth, it says it is inefficient to constantly append data to the end of an array (but it also hinted that comments are a "wierd edge case").

比方说,我们的新系统就像博客中的评论"一样-一直在动态增长,但有时也会发生变化或被删除.

Let's say our new system is like those "comments" in a blog - dynamically growing all the time, but also sometimes changing or some being deleted.

因此,在意识到使用MongoDB可能会导致性能问题之后,还有哪些其他替代数据库(必须是水平可伸缩数据库)可以满足此目的呢? (我们不介意将MongoDB用作主数据库,而是将注释"分隔为备用数据库.有哪些可用选项?

So, having recognized that there could be a performance issue using MongoDB, what other alternative database (must be horizontally scalable database) could serve this purpose? (We don't mind using MongoDB as our primary database, but separate the "comments" to a alternative database. What are the options available?

注意:

具有哈希值作为其数据类型的Redis功能符合我们的注释"数据结构的描述-不断增长,但有时被修改或删除-但是我们不需要纯粹的内存数据库(我们不希望当可以将数据持久存储到磁盘时,分配了那么多的RAM)-否则,这将很适合我们的问题

The Redis feature of having Hashes as its data types fit the description of our "comments" data structure - constantly growing but sometimes modified or deleted - BUT we do not need a pure in-memory database (we don't wish to dedicate so much RAM when the data can be persisted to the disk) - otherwise this would be a good fit for our problem

使用CouchDB怎么样?我们尚未对此产品进行调查.它如何在不断增长的数据结构中发挥作用?

What about using CouchDB? We are not investigated about this product. How does it perform with a growing data structure?

要补充以上Thilo所说的话,不嵌入具有无限增长的字段"的原因是因为这种类型的文档大小扩展会导致MongoDB具有如果文档超出分配给它的当前空间,则移动文档.您可以在文档的 Padding Factor 部分中了解有关此内容的更多信息.

To add to what Thilo said above, the reason to "not embed fields that have unbound growth" is because this type of document size expansion can cause MongoDB to have to move the document if it exceeds the current space allocated to it. You can read more about this in the Padding Factor section of the documentation.

这些类型的移动相对昂贵,尤其是如果它们频繁发生.因此,在您的主集合(最新的X等)中限制等效注释的大小(实质上限制增长),甚至可能预先填充该文档字段(实质上是手动填充)以减少注释添加/更改所引起的移动.为您值得.

Those types of moves are relatively expensive, especially if they happen frequently. Therefore limiting the size (essentially bounding that growth) of the comments equivalent in your main collection (most recent X etc.) and perhaps even pre-populating that document field (essentially manual padding) to reduce the moves caused by comment additions/changes may well be worth it for you.