skip to content

What should a team running self-managed MongoDB leave on in production: profiler level, slow-query thresholds, and who may kill an operation?

level: principalimportance: should knowfreq 36%

answer

  1. what is always on, what is time-boxed
  2. the log costs less than the collection
  3. a threshold is a budget
  4. query values are data
  5. a narrow role beats a wide one

basics

~20 s

A sensible default leaves the profiler off, ships the slow-query log with a threshold tuned to its volume, polls serverStatus, and time-boxes level 1 for investigations. Kills go to a narrow inprog and killop role, not to wide administrative roles.

solid answer

~40 s

My default: profiler level 0 everywhere, because the slow-query log already gives me what is slow without a write per operation, and it can be shipped off the box with history that a 1 MB `system.profile` cannot hold. I tune `slowOpThresholdMs` and `slowOpSampleRate` in the config file to a volume we will actually read, and accept that a high threshold hides death by a thousand small queries. A monitoring system polls `serverStatus` continuously. Level 1 is a time-boxed tool on one database, with a written end, and level 2 stays in development and test. Query values appear in both logs and profile data, so access follows data sensitivity. On-call gets a narrow role with `inprog` and `killop` rather than `clusterAdmin`. The trade-off is judgement: thresholds cost visibility, and a broad kill right costs safety.

code

yaml · 5 lines
yaml
# mongod.conf: survives restarts, unlike db.setProfilingLevel
operationProfiling:
  mode: "off"
  slowOpThresholdMs: 200
  slowOpSampleRate: 1.0

go deeper

for a junior

Recall that the profiler is off by default and that the slow-query log runs anyway, so you can often find slow operations without turning anything on.

for a middle

Explain which settings persist and where they live, how slowOpThresholdMs and slowOpSampleRate shape log volume, and which privilege actions viewing and killing operations require.

for a senior

Show you can run a time-boxed profiling session safely, read a sudden drop in slow-query lines sceptically, and limit a kill's blast radius, including on multi-document writes.

for a principal

State a default and the conditions that would change it, tie thresholds to what a team actually reads, treat diagnostics as access to data, and give on-call only the rights the job needs.

## The decision No setting is right for every deployment. A lead decides three things and writes them down: what is always on, what is switched on only during an investigation, and who may act. Each choice trades visibility against cost or risk. | Layer | Common default | Cost | Main gap | |---|---|---|---| | `serverStatus` polling | Always on | Small and steady | Instance-level only | | Slow-query log | Always on, threshold tuned | Log volume, query values in logs | Misses what sits under the threshold | | Profiler level 1 | Off, time-boxed on | A write per profiled operation | Short history, one member | | Profiler level 2 | Development and test only | A write per operation | Not a production tool | ## Profiler level The case for leaving the level at `0` is strong. The manual warns the profiler can degrade performance, particularly at level 2 or at level 1 with a low threshold, and it presents whole-instance profiling as a setup for development and test. The slow-query log gives much of the same information, needs no extra collection, and is on regardless. The case for level 1 is real but narrow. `system.profile` can be queried with the aggregation pipeline right on the server, and it can hold structured detail when no log pipeline exists. A team may reasonably keep a high-threshold level 1 on a small database where logs are hard to reach. If so, know the limits: - **History is short.** The default size is 1 MB per database and per member. - **It can switch itself off.** On 8.3 and later, a profile write waits at most `internalQueryGlobalProfilingLockDeadlineMs` (default 1 ms) for its lock and is otherwise abandoned. With more than `internalProfilingMaxAbandonedWritesPerSecondPerDb` (default 1000) abandoned writes in a second, the server sets that database's level to 0 until someone re-enables it. Watch `profiler.dbsPastThreshold`. On 8.0 none of this exists, so a busy profiler simply keeps competing. - **Runtime settings are local.** `db.setProfilingLevel` touches one process and the level does not survive a restart, so what you enable by hand can vanish, and what you intend must be in the config file. Changes are logged, which helps afterwards. ## Thresholds `slowms` defaults to 100 ms, and the manual advises setting it to the highest useful value. Choosing that value is the actual decision: - **Too low**, and the log becomes noise nobody reads, with a real cost in disk and shipping. - **Too high**, and frequent small queries that add up never appear. For those, the sum matters more than any single duration. - **`slowOpSampleRate`** lowers volume on hot systems, but a sample can miss a rare bad query, which is often the one you are looking for. - **A `filter`** gives precision, for example separate `workingMillis` and `durationMillis` thresholds, but while it is set, `slowms` and `sampleRate` are ignored, so a narrow filter can silently hide what the threshold would have shown. Since 8.0 the threshold looks at `workingMillis`, so lock waits are not counted. Teams moving from 6.0 or 7.0 may see fewer lines for the same workload and should not read that as an improvement. On 8.3 and later, `slowinprogms` logs a long-running query while it is running, which covers operations that never complete. ## Who sees query data The manual warns that the profiler can expose unencrypted query data, and slow-query lines carry command details too. So diagnostics access is data access: - The built-in `clusterMonitor` role can `find` on `system.profile`, on top of `inprog`, `serverStatus` and `top`, so a dashboards account may read query values. - **`security.redactClientLogData`** removes such values from the log but is available in MongoDB Enterprise only, and redacted logs are harder to debug. - Log retention and access then follow the same rules as the data. ## Who may kill an operation A kill has no undo for a multi-document write, so this is about limiting blast radius and keeping incidents moving. - **Narrow custom role.** The manual's example grants `killop` and `inprog` on the cluster, plus `killCursors`, and nothing else. - **Why not a built-in?** `killop` lives in `hostManager`, which also holds `shutdown`, `setParameter`, `fsync` and more, and `clusterAdmin` includes it. That is far more than on-call needs for this job. - **Own operations are already covered.** On a `mongod`, users can kill their own without `killop`, so application accounts need nothing extra. - **Prevention over cure.** `maxTimeMS` on queries, or from 8.0 the `defaultMaxTimeMS` cluster parameter for reads, cuts how often anyone needs a kill. Applying it broadly can break legitimate long reports, so exemptions need an owner. - **Review.** Successful kills are logged. Agree that each one gets a short note, because a kill hides a cause that will come back. Profiling rights sit nearby. `dbAdmin` on one database holds `enableProfiler` there, but on 9.0 changing `slowms` or `sampleRate` also needs the action on all normal databases, because those settings are global. That is a useful default: one team cannot shift a shared server's threshold. ## What the choice depends on A small team with one replica set and no log pipeline may reasonably prefer a high-threshold level 1. A platform team with central logging will rarely need it. The aim is that everyone can say what is on, why, and who may turn it off.

  • Someone proposes level 2 in production for a week to capture everything before a migration. How do you respond?
    Ask what question it answers. Level 2 adds a write per operation and, with a 1 MB capped collection, keeps little anyway. On 8.3 and later, it may also disable itself under load. I would lower the threshold for a short window, or use a `filter` and a larger `system.profile` on one secondary, time-boxed, and capture what the migration needs from the log.
  • Why might raising `slowms` make a system look healthier without improving it?
    It only moves the reporting line. Fewer lines appear while the workload stays the same, and frequent small queries remain invisible. On 8.0 and later, moving to `workingMillis` has a similar effect on lock-heavy workloads. So compare `opLatencies` and client-side latency over the same period, rather than the number of slow-query lines, before calling anything an improvement.

  • Production should always run profiler level 2, since more data is always better
  • A low slow-query threshold has no real cost because logging is free
  • If the profiler is off there is no way to see slow operations
  • Everyone on call needs clusterAdmin in order to kill an operation
  • The profiler and slow-query log hold only timings, never any query values
  • A level set by hand on one member applies across the replica set permanently

Assumes MongoDB 9.0; workingMillis dates from 8.0, while slowinprogms and the automatic disabling of the profiler arrived in 8.3, so a team on 8.0 has the first and neither of the others.