MongoDB 读取性能不佳
我有一个简单的数据集,几个集合,不超过20个 MongoDB 2.0(之前为 1.8)中的每个文档。我越来越穷了 查询数据时的结果(至少我认为它们可能是 更好地查看 http://mongoid.org/performance.html)。起初, 我认为我在 Ruby (Mongoid) 中使用的映射器是问题所在,但是 我又做了一些测试,看来与数据库更相关 本身。
我做了一个简单的基准测试,我查询同一个文档 10000 次按其 ID,首先使用 Ruby Mongo 驱动程序,然后使用 Mongoid。这 结果:
user system total real
driver 7.670000 0.380000 8.050000 ( 8.770334)
mongoid 9.180000 0.380000 9.560000 ( 10.384077)
代码在这里: https://gist.github.com/1303536 我正在测试的机器是 Core 2 Duo P8400 2.27 GHz,带有 4 运行 Ubuntu 11.04 的 GB RAM。 我也使用 pymongo 做了类似的测试来检查问题是否出在 在 Ruby 驱动程序中,但结果仅稍好一些(5-6 秒 10000 个请求)。
我正在获取的文档的 bsonsize 是 67。它有一些小的 嵌入文档,但不超过100个。部分嵌入 文档通过 ID 引用其他集合中的文档,但是 AFAIR 这 关系由映射器处理,因此它不应该影响 表现。使用 explain()
直接在数据库中获取该文档会导致 millis = 0。
奇怪的是,HDD LED 一直在闪烁。 测试。难道这个文档不应该被 Mongo 缓存在 RAM 中吗? 首先阅读?有什么明显的我可能会丢失的东西吗?或者是这个 根本不是一个糟糕的结果(但与 http://mongoid.org/performance.html 相比 看起来确实很糟糕)?
I have a simple data set, a few collections, not more than 20
documents in each, in MongoDB 2.0 (previously 1.8). I'm getting poor
results when it comes to querying data (at least I think they could be
much better looking at http://mongoid.org/performance.html). At first,
I though that the mapper I use in Ruby (Mongoid) was the problem, but
I made some more tests and it seems more related to the database
itself.
I've made a simple benchmark where I query the same document 10000
times by its ID, first using the Ruby Mongo driver, then Mongoid. The
results:
user system total real
driver 7.670000 0.380000 8.050000 ( 8.770334)
mongoid 9.180000 0.380000 9.560000 ( 10.384077)
The code is here: https://gist.github.com/1303536
The machine I'm testing this on is a Core 2 Duo P8400 2.27 GHz with 4
GB of RAM running Ubuntu 11.04.
I also made a similar test using pymongo to check if the problem lies
in the Ruby driver, but the result was only slightly better (5-6 s for
10000 requests).
The bsonsize of the document I'm fetching is 67. It has some small
embedded documents, but not more than 100. Some of the embedded
documents refer documents from other collections by ID, but AFAIR this
relationship is handled by the mapper, so it shouldn't influence the
performance. Fetching this document directly in the database with explain()
results in millis = 0.
The odd thing is that the HDD LED keeps blinking all the time during
the tests. Shouldn't this document be cached in RAM by Mongo after
first read? Is there something obvious I could be missing? Or is this
not a poor result at all (but comparing with http://mongoid.org/performance.html
it does seem bad)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我删除并重新创建了数据库。也许是因为从 1.8 到 2.0。不管怎样,HDD LED 停止闪烁,现在一切都快了 2-3 倍。
我还仔细查看了用于对 Mongoid 进行基准测试的测试,这个结果(0.001 秒)仅针对一次 find(),而不是一百万次。我告诉 Mongoid 的作者,我认为网站上没有明确说明操作数仅适用于其中的某些操作。
抱歉造成混乱。
I dropped and recreated the database. Maybe it was because of going from 1.8 to 2.0. Anyway, the HDD led stopped blinking and everything is now 2-3x times faster.
I also looked carefully at the test that was used to benchmark Mongoid and this result (0.001s) is just for one find(), not a million. I told the Mongoid's author that I think it's not stated clearly on the web site that the number of operations applies only to some of them.
Sorry for the confusion.