Hello, when I’m deleting a large amount of data in MongoDB, it’s extremely slow. Below is the log of this slow query:
{"t":{"$date":"2024-10-10T02:05:55.921Z"},"s":"I", "c":"WRITE", "id":51803, "ctx":"conn62598","msg":"Slow query","attr":{"type":"remove","ns":"xxxxx.yyyyy","command":{"q":{"_id":{"$in":[{"$oid":"66c811a63899bc0007db1127"},{"$oid":"66c862d9c3a5c70007865fc3"},{"$oid":"66c86352c356fb00078ad00d"},{"$oid":"66c86393ad55ba0007ffad34"},{"$oid":"66c8640aad55ba0007ffae7c"},{"$oid":"66c86449c356fb00078ad2b2"}]}}},"planSummary":"IXSCAN { _id: 1 }","totalOplogSlotDurationMicros":489050,"keysExamined":19952,"docsExamined":9952,"ndeleted":9484,"keysDeleted":66388,"writeConflicts":2778,"numYields":6583,"queryHash":"772EC04C","planCacheKey":"D97631C1","locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":6584}},"FeatureCompatibilityVersion":{"acquireCount":{"w":6584}},"ReplicationStateTransition":{"acquireCount":{"w":6584}},"Global":{"acquireCount":{"w":6584}},"Database":{"acquireCount":{"w":6584}},"Collection":{"acquireCount":{"w":6584}},"Mutex":{"acquireCount":{"r":25554}}},"flowControl":{"acquireCount":6584,"timeAcquiringMicros":3768},"storage":{"data":{"bytesRead":489869517,"timeReadingMicros":57729765}},"remote":"10.1.2.114:43114","durationMillis":63813},"truncated":{"command":{"q":{"_id":{"$in":{"283":{"type":"objectId","size":12}}}}}},"size":{"command":178934}}
This delete command took over 1 minute to execute, which is way beyond my expected time. I want to understand what’s happening. Is there an issue with my code?
MongoDB version: 6.0.16
Client version: spring-data-mongodb 2.1.9.RELEASE
Server specification: EC2 r6a.xlarge * 3 (4C32G)
Disk space: 900GB, IOPS 5000
Deployment type: sharded replica set, 1 primary, 2 secondaries
Let me know if you need any additional information.Any thoughts gratefully received.