2

我正在对大约 2.4MM 记录的集合运行 findAndModify 查询,查询中的所有字段都已编入索引,但是命令运行非常不一致,日志显示这需要 < 0.1 到 5 秒的时间来执行。在过去的 4 个月中,这运行得相当快,在上周它确实成为一个问题。我正在运行 MongoDB 3.0.4

更多细节,这是一个 3 个成员的副本集,1 个主副本和 2 个辅助副本。主节点正在运行有大量可用磁盘空间的wiredTiger,辅助节点在MMAPv1 上。这是写入此集合的唯一进程,并且此数据源的所有客户端都将其读取首选项设置为secondaryPreferred,因此我很确定这不是流量/负载问题。

{  
   "op":"command",
   "ns":"stats.$cmd",
   "command":{  
      "findandmodify":"MailingStat",
      "query":{  
         "endTime":{  
            "$date":"2015-09-17T08:59:59.999+0000"
         },
         "startTime":{  
            "$date":"2015-09-17T08:00:00.000+0000"
         },
         "outlet_id":{  
            "$oid":"#########"
         },
         "mailing_id":{  
            "$oid":"#########"
         }
      },
      "new":false,
      "remove":false,
      "upsert":true,
      "update":{  
         "$inc":{  
            "totalSent":1
         },
         "$set":{  
            "endTime":{  
               "$date":"2015-09-17T08:59:59.999+0000"
            },
            "startTime":{  
               "$date":"2015-09-17T08:00:00.000+0000"
            },
            "outlet_id":{  
               "$oid":"#########"
            },
            "mailing_id":{  
               "$oid":"#########"
            }
         },
         "$setOnInsert":{  
            "__v":0
         }
      }
   },
   "updateobj":{  
      "$inc":{  
         "totalSent":1
      },
      "$set":{  
         "endTime":{  
            "$date":"2015-09-17T08:59:59.999+0000"
         },
         "startTime":{  
            "$date":"2015-09-17T08:00:00.000+0000"
         },
         "outlet_id":{  
            "$oid":"#########"
         },
         "mailing_id":{  
            "$oid":"#########"
         }
      },
      "$setOnInsert":{  
         "__v":0
      }
   },
   "nscanned":1,
   "nscannedObjects":1,
   "nMatched":1,
   "nModified":1,
   "keyUpdates":0,
   "writeConflicts":0,
   "numYield":420,
   "locks":{  
      "Global":{  
         "acquireCount":{  
            "w":{  
               "$numberLong":"422"
            }
         }
      },
      "Database":{  
         "acquireCount":{  
            "w":{  
               "$numberLong":"422"
            }
         }
      },
      "Collection":{  
         "acquireCount":{  
            "w":{  
               "$numberLong":"421"
            }
         }
      },
      "oplog":{  
         "acquireCount":{  
            "w":{  
               "$numberLong":"1"
            }
         }
      }
   },
   "responseLength":308,
   "millis":2851,
   "execStats":{  

   },
   "ts":{  
      "$date":"2015-09-21T23:18:30.793+0000"
   },
   "client":"####",
   "allUsers":[  
      {  
         "user":"####",
         "db":"###"
      }
   ],
   "user":"####@$###"
}

编辑: getIndexes() 的输出

[
    {
        "v" : NumberInt(1), 
        "key" : {
            "_id" : NumberInt(1)
        }, 
        "name" : "_id_", 
        "ns" : "stats.MailingStat"
    }, 
    {
        "v" : NumberInt(1), 
        "key" : {
            "mailing_id" : NumberInt(1)
        }, 
        "name" : "mailing_id_i", 
        "ns" : "stats.MailingStat", 
        "background" : true
    }, 
    {
        "v" : NumberInt(1), 
        "key" : {
            "outlet_id" : NumberInt(1)
        }, 
        "name" : "outlet_id", 
        "ns" : "stats.MailingStat", 
        "background" : true
    }, 
    {
        "v" : NumberInt(1), 
        "key" : {
            "startTime" : NumberInt(1)
        }, 
        "name" : "startTime", 
        "ns" : "stats.MailingStat", 
        "background" : true
    }, 
    {
        "v" : NumberInt(1), 
        "key" : {
            "endTime" : NumberInt(1)
        }, 
        "name" : "endTime", 
        "ns" : "stats.MailingStat", 
        "background" : true
    }
]

编辑:从解释添加输出('queryPlanner')

{ 
    "queryPlanner" : {
        "plannerVersion" : NumberInt(1), 
        "namespace" : "stats.MailingStat", 
        "indexFilterSet" : false, 
        "parsedQuery" : {
            "$and" : [
                {
                    "endTime" : {
                        "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                    }
                }, 
                {
                    "mailing_id" : {
                        "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                    }
                }, 
                {
                    "outlet_id" : {
                        "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                    }
                }, 
                {
                    "startTime" : {
                        "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                    }
                }
            ]
        }, 
        "winningPlan" : {
            "stage" : "FETCH", 
            "filter" : {
                "$and" : [
                    {
                        "endTime" : {
                            "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                        }
                    }, 
                    {
                        "mailing_id" : {
                            "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                        }
                    }, 
                    {
                        "outlet_id" : {
                            "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                        }
                    }
                ]
            }, 
            "inputStage" : {
                "stage" : "IXSCAN", 
                "keyPattern" : {
                    "startTime" : NumberInt(1)
                }, 
                "indexName" : "startTime", 
                "isMultiKey" : false, 
                "direction" : "forward", 
                "indexBounds" : {
                    "startTime" : [
                        "[new Date(1442476800000), new Date(1442476800000)]"
                    ]
                }
            }
        }, 
        "rejectedPlans" : [
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "keyPattern" : {
                        "outlet_id" : NumberInt(1)
                    }, 
                    "indexName" : "outlet_id", 
                    "isMultiKey" : false, 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "outlet_id" : [
                            "[ObjectId('542f1477ccc0b4ec548b471d'), ObjectId('542f1477ccc0b4ec548b471d')]"
                        ]
                    }
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "keyPattern" : {
                        "mailing_id" : NumberInt(1)
                    }, 
                    "indexName" : "mailing_id_i", 
                    "isMultiKey" : false, 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "mailing_id" : [
                            "[ObjectId('55f2d561a5950e541b8e35fd'), ObjectId('55f2d561a5950e541b8e35fd')]"
                        ]
                    }
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }, 
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "keyPattern" : {
                        "endTime" : NumberInt(1)
                    }, 
                    "indexName" : "endTime", 
                    "isMultiKey" : false, 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "endTime" : [
                            "[new Date(1442480399999), new Date(1442480399999)]"
                        ]
                    }
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }, 
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "AND_SORTED", 
                    "inputStages" : [
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "outlet_id" : NumberInt(1)
                            }, 
                            "indexName" : "outlet_id", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "outlet_id" : [
                                    "[ObjectId('542f1477ccc0b4ec548b471d'), ObjectId('542f1477ccc0b4ec548b471d')]"
                                ]
                            }
                        }, 
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "startTime" : NumberInt(1)
                            }, 
                            "indexName" : "startTime", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "startTime" : [
                                    "[new Date(1442476800000), new Date(1442476800000)]"
                                ]
                            }
                        }
                    ]
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }, 
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "AND_SORTED", 
                    "inputStages" : [
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "mailing_id" : NumberInt(1)
                            }, 
                            "indexName" : "mailing_id_i", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "mailing_id" : [
                                    "[ObjectId('55f2d561a5950e541b8e35fd'), ObjectId('55f2d561a5950e541b8e35fd')]"
                                ]
                            }
                        }, 
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "startTime" : NumberInt(1)
                            }, 
                            "indexName" : "startTime", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "startTime" : [
                                    "[new Date(1442476800000), new Date(1442476800000)]"
                                ]
                            }
                        }
                    ]
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }, 
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }, 
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "AND_SORTED", 
                    "inputStages" : [
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "startTime" : NumberInt(1)
                            }, 
                            "indexName" : "startTime", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "startTime" : [
                                    "[new Date(1442476800000), new Date(1442476800000)]"
                                ]
                            }
                        }, 
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "endTime" : NumberInt(1)
                            }, 
                            "indexName" : "endTime", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "endTime" : [
                                    "[new Date(1442480399999), new Date(1442480399999)]"
                                ]
                            }
                        }
                    ]
                }
            }, 
            {
                "stage" : "FETCH", 
                "filter" : {
                    "$and" : [
                        {
                            "mailing_id" : {
                                "$eq" : ObjectId("55f2d561a5950e541b8e35fd")
                            }
                        }, 
                        {
                            "outlet_id" : {
                                "$eq" : ObjectId("542f1477ccc0b4ec548b471d")
                            }
                        }, 
                        {
                            "endTime" : {
                                "$eq" : ISODate("2015-09-17T08:59:59.999+0000")
                            }
                        }, 
                        {
                            "startTime" : {
                                "$eq" : ISODate("2015-09-17T08:00:00.000+0000")
                            }
                        }
                    ]
                }, 
                "inputStage" : {
                    "stage" : "AND_SORTED", 
                    "inputStages" : [
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "mailing_id" : NumberInt(1)
                            }, 
                            "indexName" : "mailing_id_i", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "mailing_id" : [
                                    "[ObjectId('55f2d561a5950e541b8e35fd'), ObjectId('55f2d561a5950e541b8e35fd')]"
                                ]
                            }
                        }, 
                        {
                            "stage" : "IXSCAN", 
                            "keyPattern" : {
                                "outlet_id" : NumberInt(1)
                            }, 
                            "indexName" : "outlet_id", 
                            "isMultiKey" : false, 
                            "direction" : "forward", 
                            "indexBounds" : {
                                "outlet_id" : [
                                    "[ObjectId('542f1477ccc0b4ec548b471d'), ObjectId('542f1477ccc0b4ec548b471d')]"
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }, 
    "serverInfo" : {
        "host" : "stat-web", 
        "port" : NumberInt(27017), 
        "version" : "3.0.2", 
        "gitVersion" : "6201872043ecbbc0a4cc169b5482dcf385fc464f"
    }, 
    "ok" : NumberInt(1)
}
4

0 回答 0