@@ -29,37 +29,41 @@ customize this algorithm to choose the server that works best for your applicati
29
29
Customizing the server selection algorithm might have unintended consequences,
30
30
such as degraded read or write performance.
31
31
32
- Default Algorithm
33
- -----------------
32
+ Server Selection Algorithm
33
+ --------------------------
34
34
35
35
When the {+driver-short+} executes a read operation, it performs the following steps,
36
36
in order, to select a MongoDB deployment:
37
37
38
- 1. Selects all servers that match the active read preference from the list of known servers.
38
+ 1. Selects all servers from the list of known servers suitable for the requested
39
+ operation, barring those that the driver considers unavailable or problematic
40
+
41
+ 1. For reads, selects all servers that match the active read preference
42
+
43
+ #. For writes, selects all writeable servers
39
44
40
- #. If at least one readable server exists, calls the user-defined
41
- server-selector function and passes in the list from the previous step
45
+ #. Calls the user-defined server-selector function, if the user provides one, and passes in
46
+ the list from the previous step
42
47
43
48
#. Applies the ``localThreshold`` connection setting to the list of
44
49
servers returned from the function
45
50
46
- #. Selects a server at random from the servers still on the list and
47
- executes the operation against this server
51
+ #. Selects at most two random servers from the list of servers that match the
52
+ preceding criteria, then selects the server with fewer outstanding concurrent operations
48
53
49
54
When the {+driver-short+} executes a write operation, it begins by selecting all writeable
50
55
servers from the list of known servers, not just those that match the active read preference.
51
56
The remaining steps are identical to the preceding list.
52
57
53
- To learn more about the default server selection algorithm, which the driver follows
54
- when you don't specify any custom server selection logic, see
58
+ To learn more about the MongoDB server selection algorithm, see
55
59
:manual:`Server Selection Algorithm </core/read-preference-mechanics/>` in the
56
60
{+mdb-server+} manual.
57
61
58
62
Implement Custom Server Selection Logic
59
63
---------------------------------------
60
64
61
65
You can implement your own custom server selection logic by creating a class that
62
- implements the ``ServerSelector`` interface and overrides the ``select()`` method . The following
66
+ implements the ``ServerSelector`` interface. The following
63
67
example shows a simple custom server selection class that selects servers with a ``type``
64
68
value of ``ServerType.REPLICA_SET_SECONDARY``:
65
69
0 commit comments