限制= 1 = 1毫秒,限制> 1 = 150ms(mongo-melt-down) [英] Limit = 1 = 1ms, Limit > 1 = 150ms (mongo-melt-down)

查看:44
本文介绍了限制= 1 = 1毫秒,限制> 1 = 150ms(mongo-melt-down)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MongoDB本机驱动程序,这是查询:

Using MongoDB Native Driver, here's the query:

  mo.post.find({_us:_us, utc:{$lte:utc}},{
    fields:{geo:0, bin:0, flg:0, mod:0, edt:0},
    hint:{_us:1, utc:-1},
    sort:{utc:-1},
    limit:X,
    explain:true
  }).toArray(function(err, result){
    if (err) {res.status(500).send(err);}
    else if (result.length > 0){res.status(200).json(result);}
    else {res.status(204).send();}
  });

当X(极限)为1时,响应时间为〜1ms.当我将其设置为2时,响应时间跳至+ 150ms. ......?这两个查询的解释都相同:

When X (the limit) is 1, the response time is ~1ms. When I set it to 2, the response time jumps to +150ms. Huh...? The explain for both queries are identical:

cursor: "BtreeCursor _us_1_utc_-1"
isMultiKey: false
n: 1
nscannedObjects: 1
nscanned: 1
nscannedObjectsAllPlans: 1
nscannedAllPlans: 1
scanAndOrder: false
indexOnly: false
nYields: 0
nChunkSkips: 0
millis: 0
indexBounds: {
_us: [1]
0:  [2]
0:  "54add9321656d4a9fa760b24"
1:  "54add9321656d4a9fa760b24"
-
-
utc: [1]
0:  [2]
0:  "2015-01-08T02:15:29.429Z"
1:  true

是的,它们都只显示1个扫描对象?我的索引坏了吗?即使当我将限制增加到X = 100时,响应时间仍与X = 2几乎相同,并且解释是相同的,仅显示了1个扫描对象.我不知道是怎么回事...?在RoboMongo中运行时,这些确切的查询需要不到1毫秒的时间.那么,可能是司机吗?还是toArray?

Yes, they both just show 1 scanned object? Is my index broken? Even when I increase the limit to X = 100, the response time stays pretty much the same as X = 2, and the explain is identical, just showing 1 scanned object. I have no idea what's going on...? These exact queries when run in RoboMongo take under 1ms. So, might it be the driver? or toArray?

任何帮助将不胜感激...

Any help would be appreciated...

推荐答案

2.0.x驱动程序似乎有问题:这是一个线程...

Seems to be a problem with the 2.0.x driver: here's a thread...

我只是使用2.0.x和1.4.x运行了完全相同的查询.当Limit = 1时,两者的执行速度均为〜1ms.当Limit = 2时,1.4.x版本停留在1ms左右,而2.0.x版本则跳到25ms.因此,这不仅仅是说明输出的问题-仅仅是问题的征兆.

I just ran the exact same query with 2.0.x and 1.4.x. When Limit = 1, both perform fast ~1ms. When Limit = 2, the 1.4.x version stays around 1ms but the 2.0.x version jumps to 25ms. So, it's not just an issue with the explain output - that's just a symptom of the problem.

2015年1月8日(星期四)UTC-8,上午9:04:05,约书亚·艾布拉姆斯(Joshua Abrams)写道: 有趣的是...使用1.4.x的完全相同的查询会给出正确的解释,其中n = 2(依此类推).这会影响性能吗?当我在其中Limit = 1的情况下运行查询时,速度很快(按预期),但是当Limit = 2时,速度则慢了100倍...

On Thursday, January 8, 2015 9:04:05 AM UTC-8, Joshua Abrams wrote: Interesting... exact same query using 1.4.x yields a proper explain where n = 2 (and so on). Could this be affecting performance? When I run a query where Limit = 1 it's fast (as expected) but when Limit = 2 it's 100x slower...

christkv在2015年1月8日(星期四)UTC-8上午8:52:28写道: 并不真地.我的建议是制作一个可重现的最小测试用例(代码和数据),并在jira.mongodb.com上打开票证.很难知道会发生什么.它不太可能成为驱动程序,但从未有人知道.尝试使用1.4.x分支,至少可以排除它是2.0.x分支的问题.

On Thursday, January 8, 2015 8:52:28 AM UTC-8, christkv wrote: not really. My suggestion is to make a minimal reproducible test case (code and data) and open a ticket on jira.mongodb.com. kind of hard to know what could be happening. it's unlikely to be the driver but one never knows. try with the 1.4.x branch aswell just to at least rule out that it's a 2.0.x branch issue.

2015年1月8日星期四UTC + 1下午,约书亚·艾布拉姆斯(Joshua Abrams)写道: 刚刚检查,我正在使用驱动程序的2.0.12.还有其他想法吗?

On Thursday, January 8, 2015 5:47:45 PM UTC+1, Joshua Abrams wrote: Just checked and I'm using 2.0.12 of the driver. Any other thoughts?

christkv在2015年1月8日星期四UTC-8上午8:23:16写道: 说明只是重新调整驱动程序中的所有结果,而不是部分结果.这样你就得到了计划.我想到的一件事可能是您使用的驱动程序早于1.4.19,而该错误将batchSize设置为1.

On Thursday, January 8, 2015 8:23:16 AM UTC-8, christkv wrote: explain is just retuning all the results in the driver instead of partial results. thus you get the plan. One thing that comes to mind might be that you are on a driver earlier than 1.4.19 that had an error where batchSize was set to 1.

2015年1月8日,星期四,UTC + 1,约书亚·艾布拉姆斯(Joshua Abrams)写道: 最近,我在驱动程序方面遇到了一系列性能问题. 限制= 1 = 1毫秒,限制> 1 = 150ms(mongo-melt-down)

On Thursday, January 8, 2015 5:01:42 PM UTC+1, Joshua Abrams wrote: I've been having a suite of performance issues lately with the driver. Limit = 1 = 1ms, Limit > 1 = 150ms (mongo-melt-down)

不确定是什么原因引起的-如果无法获得正确的解释,则无法调试: MongoDB本机节点驱动程序:解释被破坏了吗?

Not sure what the root cause it - and it's impossible to debug when I can't get a proper explain: MongoDB Native Node Driver: Explain is Broken?

这篇关于限制= 1 = 1毫秒,限制> 1 = 150ms(mongo-melt-down)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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