Hi, I’m running into an issue where sharding an empty collection is taking quite a long time.
I have a cluster with two shards, and sharding on a hashed custom _id, with numInitialChunks set to 4.
This is within an internal development cluster so network latency doesn’t seem to be the issue.
I have a slow query logging the create collection taking almost 94 seconds.
{"t":{"$date":"2025-03-01T10:10:31.463-08:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn53311","msg":"Slow query","attr":{"type":"command","ns":"search_data_babdc48c1b.$cmd","command":{"_shardsvrCreateCollection":"QPST.device","shardKey":{"_id":"hashed"},"unique":false,"numInitialChunks":4,"presplitHashedZones":false,"writeConcern":{"w":"majority","wtimeout":60000},"databaseVersion":{"uuid":{"$uuid":"1ea2f4fd-8e14-49a7-901c-4c642b6ab587"},"timestamp":{"$timestamp":{"t":1740852581,"i":2}},"lastMod":1},"lsid":{"id":{"$uuid":"a5b438ec-531b-4094-8375-f4100a9cfac1"},"uid":{"$binary":{"base64":"kwuo+nmBzKhO51gHonY0bO333QfSoybWEwl7Ox6mPwI=","subType":"0"}}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1740852585,"i":14}},"signature":{"hash":{"$binary":{"base64":"PuiHxutUAcL0nlgAisYdBEmejvA=","subType":"0"}},"keyId":7447642689069121537}},"$configTime":{"$timestamp":{"t":1740852584,"i":1}},"$topologyTime":{"$timestamp":{"t":1740005423,"i":5}},"$audit":{"$impersonatedUsers":[{"user":"editedoutl"}],"$impersonatedRoles":[{"role":"backup","db":"admin"},{"role":"dbAdminAnyDatabase","db":"admin"},{"role":"enableSharding","db":"admin"},{"role":"readWriteAnyDatabase","db":"admin"},{"role":"restore","db":"admin"}]},"$client":{"driver":{"name":"PyMongo","version":"3.12.3"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.4.0-204-generic"},"platform":"CPython 3.6.15.final.0","mongos":{"host":"internalrouter:27017","client":"someclient:55890","version":"6.0.19"}},"mayBypassWriteBlocking":true,"$db":"search_data_babdc48c1b"},"numYields":0,"reslen":334,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":1}},"FeatureCompatibilityVersion":{"acquireCount":{"r":1}},"ReplicationStateTransition":{"acquireCount":{"w":1}},"Global":{"acquireCount":{"r":1}},"Database":{"acquireCount":{"r":1}},"Mutex":{"acquireCount":{"r":2}}},"writeConcern":{"w":"majority","wtimeout":60000,"provenance":"clientSupplied"},"remote":"192.168.1.191:35260","protocol":"op_msg","durationMillis":94182}}
The work flow is that I’m creating an empty database, enabling sharding - then issuing many shard collections on that database asynchronously. I do this before data ingestion occurs. However It looks like I have to wait a significant amount of time (4 minutes) to just shard 4 empty collections. What could be the cause of this?