Running the MongoDB Profiler
5 min
Customers experiencing Swimlane Platform performance problems may be asked to assist in gathering diagnostic data, including the identification of long-running, poor-performing MongoDB queries. This is done in MongoDB admin clients (such as Robo 3T and the mongo shell) as follows:
- Connect to the Swimlane database.
use Swimlane
- Discard the contents of previous profiling sessions.
db.system.profile.drop()
- Enable the profiler making a thoughtful choice about what query duration to capture. The following will cause only queries running longer than 2 seconds (2000 ms) to be captured.
db.setProfilingLevel(2, { slowms: 2000 })
- Demonstrate the problem symptom. Perform whatever operations are necessary within Swimlane to re-create the poor performance scenario. While poor performance is ongoing use
db.system.profile.count()
to see how quickly the collection db.system.profile is filling up. It has a 1 MB maximum size, and so it will accommodate several hundred captured queries. See below for instructions to increase this maximum size if needed.
- Stop the profiler (leave it running for 30 seconds after re-creating the poor performance).
db.setProfilingLevel(0)
- Export the entire system.profile collection. Then, attach it to your Support Portal ticket. Step 1: Set the namespace
$ export NS=<ENTER NAMESPACE HERE>
Step 2: Identify which mongo pod is primary
$ kubectl exec mongo-0 -n $NS -- mongo -u Admin -p --authenticationDatabase admin --ssl --sslAllowInvalidHostnames --sslAllowInvalidCertificates admin --eval="rs.isMaster();" | grep primary
Step 3: Export the system.profile collection. In the example below, swimlane-sw-mongo-0 is PRIMARY.
$ kubectl exec mongo-0 -n $NS -- /bin/bash -c "mongoexport -u Admin -p --authenticationDatabase admin --ssl --sslAllowInvalidCertificates --db Swimlane --collection system.profile" > /tmp/system-profile-data-mongo.json
- Submit /tmp/system-profile-data-mongo.json to Support
- It may be necessary to repeat the above procedure several times to ensure that the poorest performing queries are captured for analysis. Keep these tips in mind:
- As directed by Swimlane Support, it may be necessary to alter the slowms parameter in step 3.
- Reduce slowms if no queries are being captured.
- Increase slowms if too many queries are being captured.
- Alternately, increase the maximum size limit of db.system.profile by issuing this command, db.createCollection( "system.profile", { capped: true, size:4000000 } ), after step 2 and before step 3.
- For more information, see https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/ section Change Size of system.profile Collection on the Primary.