Add a new sampleRate parameter to the profile command. This parameter can take values on the interval [0, 1], and is set to 1 by default on startup. The behavior of sampleRate is as follows for logging:
- If the logLevel is 0, then we log a slow command that exceeds the slowms with probability given by sampleRate. Commands whose latency is less than slowms, as before, are not logged.
- If the logLevel is 1 or higher, then all commands are logged. The sampleRate has no affect in this case.
For creating system.profile entries, the behavior of sampleRate is as follows:
- If the profiling level is 0, then no profile entries are created and sampleRate takes no affect.
- If the profiling level is 1, then an operation exceeding slowms is profiled with probability given by sampleRate.
- If the profiling level is 2, then all operations are profiled with probability given by sampleRate, regardless of latency.
There are three ways to set the profiler sampleRate. The first is by running the profile command. For example, the following command indicates that the server should profile 10% of operations slower than 30ms:
This command will return the previous settings of profile, slowms, and sampleRate on success. Like slowms, the sampleRate setting is unchanged when it is omitted from the command. The sampleRate can also be set from the shell using the db.setProfilingLevel() helper:
The second argument to this helper is now either the slowms value, or an options object.
The second way to set sampleRate is the new slowOpSampleRate command line option:
Third, it can be set in a configuration file using operationProfiling.slowOpSampleRate.