0

我正在为我的一个项目使用流星。我有一个零星的问题,有时一两个查询需要很长时间。例如,以下日志取自 MongoDB 日志,其中每个块的最后一部分提到了查询所用的时间(以毫秒为单位)。

可以看出,第 4 条和第 5 条日志分别显示 14774 毫秒和 17163 毫秒,其他几乎比这些值小 14-17 倍。对于需要很长时间的查询,我只能看到IXSCAN值从{ value: 1 }变为。{ r.lid: 1 }在谷歌搜索了一下之后,IXSCAN我知道它选择了要扫描的索引。我有以下问题,

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

[conn252] 查询 cdk.WLCV 查询:{ $query: { cid: "C1", uid: "W1", r.lid: "L12", value: { $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", value: { $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", value: { $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", value: { $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", value: { $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", value: { $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", value: { $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 分辨率:63246 105 毫秒

[conn251] 查询 cdk.WLCV 查询:{ $query: { cid: "C8", uid: "W1", r.lid: "L12", value: { $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 分辨率:63650 134 毫秒

[conn252] 查询 cdk.WLCV 查询:{ $query: { cid: "C9", uid: "W1", r.lid: "L12", value: { $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 分辨率:63650 143 毫秒

以下是我从 mongo 控制台获得的数据库统计信息。

{
    "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
}
4

0 回答 0