約 2.4MM レコードのコレクションに対して findAndModify クエリを実行しています。クエリ内のすべてのフィールドにインデックスが付けられていますが、コマンドの実行に一貫性がありません。ログには、実行に 0.1 秒未満から 5 秒かかることが示されています。過去 4 か月間で、これはかなり急速に進みました。この 1 週間で本当に問題になりました。MongoDB 3.0.4 を実行しています
詳細については、これは 3 つのメンバーの replicaSet、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
}
]
編集: Explain('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)
}