Details
-
New Feature
-
Resolution: Done
-
Major - P3
-
None
-
2.2.2
-
None
Description
Motivation
In replica-set environments with high bulk inserts, where stale reads are acceptable and read performance is critical, it would be very useful to attempt to find a replica set member that is not holding or pending a write lock. Read performance is expected to improve.
Please note that the below proposal is only an attempt at explaining one (of many) possible implementations of this feature.
Prerequisite
In order to facilitate the algorithm that is proposed below, a write lock level or similar construct is required to be introduced. In addition, each replica set member needs to be able to instantly respond on the current write lock level and with whether or not it is a write lock is pending. The write lock level may be determined by the duration of similar previous write operations, or through other heuristics.
Read Preference Algorithm
Scenario
A client driver receives a read request where the readPreferenceMode has been specified as avoidWriteLock
where n is the minimum write lock level to avoid.
Algorithm (pseudo-code)
Server getReadServerAvoidingWriteLock(int writeLockLevel)
|
{
|
foreach(Server m in ReplicaSetMembers)
|
{
|
if (!m.isHoldingOrPendingWriteLock(writeLockLevel))
|
{
|
return m;
|
}
|
}
|
return getReadServerSecondaryPreferred();
|
}
|