-
Type: Bug
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Sharding
-
Labels:None
-
Sharding
-
ALL
The CollectionShardingState must be accessed on nearly every operation in a sharded cluster, which leads to a lot of contention on this mutex, as seen in a local perf run (though of course that's not a perfect representation). Because currently we never delete items from the map (it's append-only), and we only rarely add new items (on sharded collection creation), I think it would be a good candidate for a lock-free copy-on-write data structure, which would allow reads which do not create new entries to occur with only a few atomic reads rather than a full mutex acquisition. It would be pretty easy to try this and perf test it. At the very least, we could change the mutex to a ResourceMutex so that reads only require a SharedLock rather than an exclusive lock.