我正在使用 prometheus/grafana/mongodb_exporter 監視我的 ~10TB 5x shards 分片集群,但我看到 mongo_exporter 正在從 CSRS 服務器獲取按分片分組的塊數,并且需要超過 2 分鐘:
2022-01-18T16:31:48.499 0100 I COMMAND [conn369096] command config.chunks appName: "mongodb_exporter" command: aggregate { aggregate: "chunks", pipeline: [ { $group: { _id: "$shard", count: { $sum: 1 } } } ], fromMongos: true, cursor: { batchSize: 101 }, lsid: { id: UUID("4b65f5f9-1776-471e-a086-3bee46841edf"), uid: BinData(0, 745F9C5E38C046A7EAF9555E7B0195569974DC916F6DF649D96D26158C1DF113) }, $readPreference: { mode: "secondaryPreferred" }, $replData: 1, $clusterTime: { clusterTime: Timestamp(1642519905, 7), signature: { hash: BinData(0, CA16F59A62FEE55E3A1B73F5A45E450B4EFE5F88), keyId: 7004436913486561282 } }, $client: { driver: { name: "mongo-go-driver", version: "v1.5.3" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.16.5", application: { name: "mongodb_exporter" }, mongos: { host: "mymongos:27019", client: "1.2.3.4:54054", version: "4.0.23" } }, $configServerState: { opTime: { ts: Timestamp(1642519905, 7), t: 120 } }, $db: "config" } planSummary: COLLSCAN keysExamined:0 docsExamined:1620394 cursorExhausted:1 numYields:12684 nreturned:5 reslen:707 locks:{ Global: { acquireCount: { r: 12757 } }, Database: { acquireCount: { r: 12757 } }, Collection: { acquireCount: { r: 12757 } } } storage:{} protocol:op_msg 2464ms
所以問題:
在 CSRS config.chunks.shard 欄位中創建索引以加快此定期 mongodb_exporter 聚合查詢是否明智?經過測驗的索引創建,我看到聚合查詢僅在通過 HINT 明確建議時才拾取它:
CSRS:PRIMARY> db.chunks.createIndex({shard:1}) CSRS:PRIMARY> db.chunks.explain("executionStats").aggregate([ { $group: { _id: "$shard", count: { $sum: 1 } } }],{hint:{"shard":1}} ) "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "shard" : 1 }, "executionStats" : { "executionSuccess" : true, "nReturned" : 1601762, "executionTimeMillis" : 1377, "totalKeysExamined" : 1601762, "totalDocsExamined" : 0 CSRS:PRIMARY> db.chunks.aggregate([ { $group: { _id: "$shard", count: { $sum: 1 } } }],{hint:{"shard":1}} ) { "_id" : "s4", "count" : 318174 } { "_id" : "s3", "count" : 318086 } { "_id" : "s0", "count" : 317933 } { "_id" : "s1", "count" : 318020 } { "_id" : "s2", "count" : 329549 } CSRS:PRIMARY>
- 請建議在 CSRS 配置資料庫中添加自定義索引是否安全?
任何建議將不勝感激?
uj5u.com熱心網友回復:
您的查詢涵蓋所有集合,但通常它應該是每個集合,即每個命名空間。在早期的 MongoDB 版本中,檔案如下所示:
{
"_id": ObjectId("61a7bd45b9a53380435dede7"),
"ns": "database.collection",
"min": ...,
"max": ....,
"shard": "shard_02",
...
}
現在在 MongoDB 5.0 中,欄位ns被替換為uuid如下所示:
{
"_id": ObjectId("61a7bd45b9a53380435dede7"),
"uuid": UUID("322758c1-c52f-4ab6-9eb2-c48fc1634ef7"),
"min": ...,
"max": ....,
"shard": "shard_02",
...
}
你應該有一個唯一的索引{uuid: 1, shard: 1, min: 1}。config.collections您可以從集合中查找命名空間。
也許 prometheus/grafana 沒有考慮到這個修改。
如果滿足以下所有條件,該$group階段有時可以使用索引來查找每個組中的第一個檔案:
- 該
$group階段之前是一個$sort階段,該階段對要分組的欄位進行排序, - 分組欄位上有一個與排序順序匹配的索引,并且
$group舞臺中使用的唯一蓄能器是$first.
所以,我認為索引{shard: 1}不會有幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/414712.html
標籤:
上一篇:具有值條件的陣列中的重復項
