Lock acquiring time for a MongoDB Document

I got this below the log in the MongoDB slow query log. I have the MongoDB version running 5.0 with 3 shards in PSS mode.

The query is running on the primary key and the total document size is 800KB, in the below query, I see time spent on locks is around 12 seconds.

How can I reduce this time?

{
	"t": {
		"$date": "2023-03-14T18:02:45.788+05:30"
	},
	"s": "I",
	"c": "WRITE",
	"id": 51803,
	"ctx": "conn1830718",
	"msg": "Slow query",
	"attr": {
		"type": "update",
		"ns": "db_name.XXXXXX",
		"command": {
			"q": {
				"uid": 307126413
			},
			"u": {
				"$push": {
					"psfd": {
						"$each": [{
							"mid": 5373,
							"aid": 1488,
							"trid": "89461-5373-307126413-1488-230313105553",
							"guid": "f0aeafbe-a05b-4519-b2bd-277f383febce",
							"st": "drop",
							"dt": 230313105553,
							"adw": 2,
							"ad": 230313,
							"at": 105553
						}],
						"$slice": -5000
					}
				}
			},
			"multi": false,
			"upsert": false
		},
		"planSummary": "IXSCAN { uid: 1 }",
		"keysExamined": 1,
		"docsExamined": 1,
		"nMatched": 1,
		"nModified": 1,
		"nUpserted": 0,
		"numYields": 0,
		"queryHash": "B34121E2",
		"planCacheKey": "CFF4BBD8",
		"locks": {
			"ParallelBatchWriterMode": {
				"acquireCount": {
					"r": 320
				}
			},
			"ReplicationStateTransition": {
				"acquireCount": {
					"w": 333
				}
			},
			"Global": {
				"acquireCount": {
					"r": 12,
					"w": 320
				}
			},
			"Database": {
				"acquireCount": {
					"w": 320
				}
			},
			"Collection": {
				"acquireCount": {
					"w": 320
				}
			},
			"Mutex": {
				"acquireCount": {
					"r": 700
				}
			}
		},
		"flowControl": {
			"acquireCount": 180,
			"acquireWaitCount": 13,
			**"timeAcquiringMicros": 12288598**
		},
		"storage": {
			"data": {
				"bytesRead": 31243557,
				"timeReadingMicros": 64674
			}
		},
		"remote": "172.31.22.28:35548",
		"durationMillis": 794
	}
}

Hey @Kathiresh_Nadar,

I suspect that there could be several different reasons for the high timeAcquiringMicros value, e.g. hardware, other operations, or other factors.

Can you please share the following information in order to repro it in my environment:

  • Sample documents.
  • Expected output.
  • Number of documents in the collection.
  • The query you executed.
  • Output from what you have attempted.

Best,
Kushagra