草庐IT

MongoDb 与 Cassandra :Read/Write myths?

coder 2023-05-05 原文

在网上阅读几篇关于 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/

有关MongoDb 与 Cassandra :Read/Write myths?的更多相关文章

  1. ruby CSV : How can I read a tab-delimited file? - 2

    CSV.open(name,"r").eachdo|row|putsrowend我得到以下错误:CSV::MalformedCSVErrorUnquotedfieldsdonotallow\ror\n文件名是一个.txt制表符分隔文件。我是专门做的。我有一个.csv文件,我转到excel,并将文件保存为.txt制表符分隔的文件。所以它是制表符分隔的。CSV.open不应该能够读取制表符分隔的文件吗? 最佳答案 尝试像这样指定字段分隔符:CSV.open("name","r",{:col_sep=>"\t"}).eachdo|row|

  2. ruby - File.read ("| echo mystring") 是如何工作的? - 2

    我在我正在处理的一些代码中发现了这一点。它旨在解决从磁盘读取key文件的要求。在生产环境中,key文件的内容位于环境变量中。旧代码:key=File.read('path/to/key.pem')新代码:key=File.read('|echo$KEY_VARIABLE')这是如何工作的? 最佳答案 来自IOdocs:Astringstartingwith“|”indicatesasubprocess.Theremainderofthestringfollowingthe“|”isinvokedasaprocesswithappro

  3. ruby - 如何通过 Rubocop 指示打开 & :read as argument to File. - 2

    我有这个代码File.open(file_name,'r'){|file|file.read}但是Rubocop发出警告:Offenses:Style/SymbolProc:Pass&:readasargumenttoopeninsteadofablock.你是怎么做到的? 最佳答案 我刚刚创建了一个名为“t.txt”的文件,其中包含“Hello,World\n”。我们可以按如下方式阅读。File.open('t.txt','r',&:read)#=>"Hello,World\n"顺便说一下,由于第二个参数的默认值是'r',所以这样

  4. ruby - Chef : Read variable from file and use it in one converge - 2

    我有以下代码,它下载一个文件,然后将文件的内容读入一个变量。使用该变量,它执行一个命令。这个配方不会收敛,因为/root/foo在编译阶段不存在。我可以通过多个聚合和一个来解决这个问题ifFile.exist但我想用一个收敛来完成它。关于如何做到这一点有什么想法吗?execute'download_joiner'docommand"awss3cps3://bucket/foo/root/foo"not_if{::File.exist?('/root/foo')}endpassword=::File.read('/root/foo').chompexecute'join_domain'd

  5. Ruby:read_timeout 和 open_timeout 之间的区别 - 2

    标题本身就说明了......read_timeout和open_timeout之间有什么区别? 最佳答案 open_timeout是您愿意等待“打开连接”的时间。在TCP上下文中,在放弃尝试并引发超时错误之前等待握手完成的时间量。read_timeout您可能会猜到,是您愿意等待从连接方接收到某些数据的时间。一个例子可能会清楚地说明这一点:在SOAPoverHTTPoverTCP上下文中(简化):您尝试与服务器建立TCP连接。如果建立连接的时间比open_timeout长,则放弃连接尝试并引发/发出/返回超时错误。如果连接成功,您发

  6. ruby - 如何强制 Rack :session + sinatra to read "rack.session" from params instead of cookies - 2

    我正在处理oauth1.0(twitter和flickr)。网站工作在80端口,oauth服务器工作在8080端口算法:向oauth服务器发送ajax请求以检查用户是否有有效的access_token如果用户没有access_token或access_token已过期,则打开授权窗口在oauth服务器的用户session中保存access_token发送分享数据到oauth服务器它使用sinatra+rack:session+rack::session::sequel+sqlite来存储session。它在每个响应中发送Set-Cookie:rack.session=id我正在使用2种

  7. ruby - 简单的问题 : Read file, 在 Ruby 中反转它并写入另一个文件 - 2

    我有:o=File.new("ouput.txt","rw+")File.new("my_file.txt").lines.reverse_each{|line|?????line}o.close不知道用什么方法写入文件输出o 最佳答案 puts理解数组,因此您可以将其简化为:File.open("f2.txt","w"){|o|o.putsFile.readlines("f1.txt").reverse} 关于ruby-简单的问题:Readfile,在Ruby中反转它并写入另一个文件,

  8. 已解决socket.timeout : The read operation timed out - 2

    已解决(pip安装模块超时,利用四种国内镜像源完美解决)WARENTING:Retrying(Retry(total=4,connect=None,read=None,redirect=None,status=None))afterconnectionbrokenby‘ConnectTimeoutError(pip._vendor.urllib3.connection.HTTPSConnectionobjectatOx00001D6OE4F4A940>,‘Connectiontopypi.orgtimedout.(connecttimeout=15)’)’':/simple/pip/socke

  9. ruby-on-rails - rails 3.2.8 中未定义的 read_inheritable_attribute - 2

    升级到rails3.2.8后出现以下错误信息NoMethodError(undefinedmethod`read_inheritable_attribute'forAdminController:Class):谁能解释一下如何解决这个错误?整个轨迹NoMethodError(undefinedmethod`read_inheritable_attribute'forAdminController:Class):vendor/plugins/ssl_requirement/lib/ssl_requirement.rb:45:in`ssl_allowed?'vendor/plugins/s

  10. ruby - 学习 Ruby : recommended blogs to read? - 2

    关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于StackOverflow来说是偏离主题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,describetheproblem以及迄今为止为解决该问题所做的工作。关闭8年前。Improvethisquestion我即将开始学习Ruby,想要一些阅读Material来帮助我融入其中。我正在寻找你在Ruby上的前5博客、新闻和任何(活跃的)公告板(我可以很好地处理新闻组,但我更喜欢在BB中阅读)。谢谢,

随机推荐