MongoDb 与 Cassandra :Read/Write myths?

标签 mongodb cassandra nosql

在网上阅读几篇关于 MongoDB 与 Cassandra 读/写性能的文章,

一般来说,Cassandra 的写入性能在数据量很大的情况下比 Mongo 的要好。请参阅下面的声明。

Cassandra's storage engine provides constant-time writes no matter how big your data set grows. Writes are more problematic in MongoDB, partly because of the b-tree based storage engine, but more because of the per database write lock.

这是我的问题:- 这个陈述仍然正确吗?据我了解,Mongo 支持每个文档而不是每个数据库的锁定。正确的?那么目前Cassandra在写性能上还是比Mongo更好吗?如果是,为什么?

阅读

一般来说,Mongo 的读取性能比 Cassandra 好,但我没有找到任何理由让 Mongo 的读取性能优于 Cassandra 的?

更新:-

来自 Jared Answer 的 this forum

Reads are more efficient in MongoDB's storage engine than they are in Cassandra. Cassandra's storage engine performs very well on writes because it stores data in an append only format. This makes great use of spinning disk drives that have poor seek times, but can do serial writes very quickly. But the downside is that when you do a read, you often need to scan through several versions of an object to get the most recent version to return to the caller. MongoDB updates data in place. This means it does more random IO when writes are processed, but it has the benefit of being faster when processing reads, since you can find the exact location of the object on disk in one b-tree lookup.

它帮助我了解 Cassandra 在删除/编辑现有记录时更快,因为它必须最后附加它,而不是像 Mongo 那样必须先搜索然后编辑它的地方编辑。这使得 cassandra 在编写方面比 Mongo 更好

但同样的事情让 Mongo 比 Cassandra 慢,因为 Cassandra 必须扫描同一记录的多个版本才能获取最新版本以返回给调用者

另一个原因是blog为什么 cassandra 写得更好

MongoDB with its “single master” model can take writes only on the primary. The secondary servers can only be used for reads. So essentially if you have three node replica set, only the master is taking writes and the other two nodes are only used for reads. This greatly limits write scalability. You can deploy multiple shards but essentially only 1/3 of your data nodes can take writes. Cassandra with its “multiple master” model can take writes on any server. Essentially your write scalability is limited by the number of servers you have in the cluster. The more servers you have in the cluster, the better it will scale.

来自同一个blog为什么 Mongo 在阅读方面比 cassandra 好

Secondary indexes are a first-class construct in MongoDB. This makes it easy to index any property of an object stored in MongoDB even if it is nested. This makes it really easy to query based on these secondary indexes. Cassandra has only cursory support for secondary indexes. Secondary indexes are also limited to single columns and equality comparisons. If you are mostly going to be querying by the primary key then Cassandra will work well for you.

最佳答案

问题的答案: 是的。最新的 MongoDB 支持每个文档的锁https://docs.mongodb.com/manual/core/wiredtiger/

以下是写操作的基准:https://www.datastax.com/nosql-databases/benchmarks-cassandra-vs-mongodb-vs-hbase 根据这些基准, Cassandra 在规模上表现更好(在集群中的节点数量较多时)。

希望对您有所帮助。

以下是有关您的问题的一些详细信息,可能也会有所帮助。

关于 Cassandra

Cassandra 正在使用针对大量写入进行了优化的 LSM-tree。 https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_manage_ondisk_c.html

一些细节:

执行写入时,数据会立即写入提交日志。提交日志是一种崩溃恢复机制。在写入提交日志之前,写入不会被视为成功。 数据写入commit log后,写入memtable。在最新版本的 Cassandra 中,memtable 主要存储在 native 内存中,而不是 JVM 堆中。所以它也提高了性能。

当存储在 memtable 中的对象数量达到阈值时,memtable 的内容会在称为 SSTable 的文件中刷新到磁盘。然后创建一个新的内存表。一旦一个 memtable 被刷新到一个 SSTable,它就是不可变的。

向 Cassandra 写入值不需要任何类型的读取或查找,因为所有写入都是追加操作。

关于 MongoDB

默认情况下,MongoDB 使用 MMAPv1 存储引擎,该引擎使用 B-tree (https://docs.mongodb.com/manual/core/mmapv1/),但最近版本的 MongoDB 使用 WiredTiger 存储引擎 (https://docs.mongodb.com/manual/core/wiredtiger/),它也可以支持 LSM-tree。

关于锁:WiredTiger MongoDB 支持文档级锁,但 MMAPv1 支持集合级并发控制。

一些有用的文章:
https://dba.stackexchange.com/questions/121160/mongodb-mmapv1-vs-wiredtiger-storage-engines
https://docs.mongodb.com/manual/faq/concurrency/
https://www.percona.com/blog/2016/01/06/mongodb-revs-you-up-what-storage-engine-is-right-part-1/

关于MongoDb 与 Cassandra :Read/Write myths?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970547/

相关文章:

nosql - 在哪里可以找到有关 NOSQL 实现模式的信息?

amazon-web-services - 从 DynamoDB 中的 startTime 和 endTime 字段查询时间范围?

javascript - 根据MongoDB中另一个集合中的数据查询一个集合中的数据

python - DataFrame 到 Json 使用第一列作为键,第二列作为值

MongoDB - 安全/永久删除敏感数据(文档),使其无法恢复

hadoop - 如何从另一个列中填充 Cassandra 列族?

java - 我应该为 "com.datastax.driver.core.exceptions.ReadTimeoutException"做什么?

linux - MongoDB,非root的Ubuntu用户,PID文件存放在/var/run/mongodb

java - 使用 Astyanax 客户端将数据更新到 Cassandra 数据库中

nosql - Elasticsearch - 标记强度(嵌套/子文档增强)