DBAtlas · データベース運用アトラス

プロファイラーのデータから最も遅いクエリとクエリシェイプを抽出する

MongoDBパフォーマンス

コマンド

// Recent slow operations (in the db where profiling is on; see set-profiling):
db.system.profile.find({ millis: { $gte: 100 } }, { ts: 1, ns: 1, op: 1, millis: 1, planSummary: 1, keysExamined: 1, docsExamined: 1, nreturned: 1, appName: 1 }).sort({ ts: -1 }).limit(20)
// Total time per query shape (those consuming the most time):
db.system.profile.aggregate([
  { $group: { _id: { ns: "$ns", plan: "$planSummary", shape: "$queryHash" }, n: { $sum: 1 }, totalMs: { $sum: "$millis" }, maxMs: { $max: "$millis" }, avgDocs: { $avg: "$docsExamined" } } },
  { $sort: { totalMs: -1 } },
  { $limit: 10 }
])
// Queries not using an index (COLLSCAN):
db.system.profile.find({ planSummary: "COLLSCAN" }, { ns: 1, millis: 1, command: 1 }).sort({ millis: -1 }).limit(10)

概要

system.profile コレクションのレコードから、最近の低速操作、クエリシェイプ (queryHash) ごとの合計時間、インデックスを使用しない COLLSCAN クエリを一覧表示する。

使用する場面

低速化の苦情に対し、どのクエリがサーバー時間を消費しているかを特定し、インデックスの必要性を判断するため。

注意

system.profile はデフォルトで 1 MB の capped コレクションで、データベースごとに存在する。高負荷システムではレコードが数分でロールオーバーするため、プロファイリングが有効な間かその直後に分析する。プロファイリングレベル 2 または slowms 0 はすべての操作を書き込み、大きなオーバーヘッドを生じる。レコードは実行されたメンバー上にのみ保持され、レプリケートされない。

DBAtlas で開く →

関連項目