DBAtlas · Atlas für Datenbankbetrieb

Die langsamsten Abfragen und Query Shapes aus Profiler-Daten ermitteln

MongoDBPerformance

Befehl

// 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)

Was es tut

Listet aus den Einträgen der Collection system.profile die letzten langsamen Operationen, die Gesamtzeit pro Query Shape (queryHash) und COLLSCAN-Abfragen ohne Indexnutzung.

Wann einsetzen

Bei einer Beschwerde über Langsamkeit, um herauszufinden, welche Abfrage Serverzeit verbraucht, und um den Indexbedarf zu bestimmen.

Vorsicht

system.profile ist standardmäßig eine Capped Collection mit 1 MB und gilt pro Datenbank; auf einem ausgelasteten System rotieren die Einträge innerhalb von Minuten, analysiere daher bei aktivem Profiling oder direkt danach. Profiling-Level 2 oder slowms 0 schreibt jede Operation und erzeugt erheblichen Overhead. Einträge werden nur auf dem Mitglied gehalten, auf dem sie liefen, und nicht repliziert.

In DBAtlas öffnen →

Verwandte Einträge