Meteor mongo查询需要很长时间

时间:2015-09-02 08:28:50

标签: mongodb meteor node-fibers

我正在为我的一个项目使用meteor。我有一个零星的问题,有时一两个查询需要很长时间。例如,以下日志取自mongodb日志,其中每个块的最后部分提到查询所用的时间(以毫秒为单位)。可以看出,第4和第5个日志分别显示14774ms和17163ms,其他几乎比这些值小14-17倍。对于需要很长时间的查询,我只能看到IXSCAN值从{ value: 1 }更改为{ r.lid: 1 }。在谷歌搜索IXSCAN之后,我发现它选择了扫描索引。我有以下问题,

  • 为什么为某些查询选择了错误的索引,尽管它们都是由相同的代码引发并且具有相同的查询属性?
  • 有没有办法强制此查询的索引(最好是来自meteor)
  • 虽然与此无关,但为什么会创建许多连接(如每行conn2XX的开头所示)。我正在使用node-fiber来查询并行后台请求。有没有办法杀死这些连接?
  

[conn252]查询cdk.WLCV查询:{$ query:{cid:“C1”,uid:“W1”,r.lid:“L12”,值:{$ gte:1031,$ lte:1107} },orderby:{value:1}} planSummary:IXSCAN {value:1} ntoreturn:0 ntoskip:0 nscanned:59754 nscannedObjects:59754 keyUpdates:0 numYields:0 locks(micros)r:155165 nreturned:77 reslen:48530 155ms

     

[conn251]查询cdk.WLCV查询:{$ query:{cid:“C2”,uid:“W1”,r.lid:“L12”,值:{$ gte:1031,$ lte:1107} },orderby:{value:1}} planSummary:IXSCAN {value:1} ntoreturn:0 ntoskip:0 nscanned:59754 nscannedObjects:59754 keyUpdates:0 numYields:0 locks(micros)r:172445 nreturned:78 reslen:49160 172ms

     

[conn248]查询cdk.WLCV查询:{$ query:{cid:“C3”,uid:“W1”,r.lid:“L12”,值:{$ gte:1031,$ lte:1107} },orderby:{value:1}} planSummary:IXSCAN {value:1} ntoreturn:0 ntoskip:0 nscanned:59754 nscannedObjects:59754 keyUpdates:0 numYields:0 locks(micros)r:161176 nreturned:77 reslen:48222 161ms

     

[conn249]查询cdk.WLCV查询:{$ query:{cid:“C4”,uid:“W1”,r.lid:“L12”,值:{$ gte:1031,$ lte:1107} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:11037 locks(micros)r:1384301 nreturned: 77 reslen:48684 14774ms`

     

[conn250]查询cdk.WLCV查询:{$ query:{cid:“C5”,uid:“W1”,r.lid:“L12”,值:{$ gte:1031,$ lte:1107} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:9464 locks(micros)r:1904782 nreturned: 77 reslen:48761 17163ms

     

[conn249]查询cdk.WLCV查询:{$ query:{cid:“C6”,uid:“W1”,r.lid:“L12”,值:{$ gte:790,$ lte:940} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} cursorid:305719783659 ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:0 locks(micros)r: 114383 nreturned:101 reslen:63650 114ms`

     

[conn250]查询cdk.WLCV查询:{$ query:{cid:“C7”,uid:“W1”,r.lid:“L12”,值:{$ gte:790,$ lte:940} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} cursorid:305713399194 ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:0 locks(micros)r: 105275 nreturned:101 reslen:63246 105ms

     

[conn251]查询cdk.WLCV查询:{$ query:{cid:“C8”,uid:“W1”,r.lid:“L12”,值:{$ gte:790,$ lte:940} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} cursorid:306335307165 ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:0 locks(micros)r: 134425 nreturned:101 reslen:63650 134ms

     

[conn252]查询cdk.WLCV查询:{$ query:{cid:“C9”,uid:“W1”,r.lid:“L12”,值:{$ gte:790,$ lte:940} },orderby:{value:1}} planSummary:IXSCAN {r.lid:1} cursorid:306643211432 ntoreturn:0 ntoskip:0 nscanned:46147 nscannedObjects:46147 scanAndOrder:1 keyUpdates:0 numYields:0 locks(micros)r: 143227 nreturned:101 reslen:63650 143ms

以下是我从mongo控制台获取的db统计信息。

{
    "ns" : "cdk.WLCV",
    "count" : 8891054,
    "size" : 8962182432,
    "avgObjSize" : 1008,
    "storageSize" : 9305935856,
    "numExtents" : 25,
    "nindexes" : 8,
    "lastExtentSize" : 2146426864,
    "paddingFactor" : 1,
    "systemFlags" : 1,
    "userFlags" : 1,
    "totalIndexSize" : 3600456944,
    "indexSizes" : {
        "_id_" : 544161856,
        "uid_1" : 612635856,
        "cid_1" : 357135856,
        "r.lid_1" : 484370768,
        "r.m" : 366898000,
        "value_1" : 318700480,
        "mvalue_1" : 359400608,
        "r.did_1" : 557153520
    },
    "ok" : 1
}

非常感谢任何帮助。提前谢谢。

0 个答案:

没有答案