1
+ .. _csharp-server-selection:
2
+
1
3
==========================
2
4
Customize Server Selection
3
5
==========================
@@ -24,7 +26,7 @@ customize this algorithm to choose the server that works best for your applicati
24
26
25
27
.. important::
26
28
27
- Customizing the server- selection algorithm can have unintended consequences,
29
+ Customizing the server selection algorithm might have unintended consequences,
28
30
such as degraded read or write performance.
29
31
30
32
Default Algorithm
@@ -33,46 +35,45 @@ Default Algorithm
33
35
When the {+driver-short+} executes a read operation, it performs the following steps,
34
36
in order, to select a MongoDB deployment:
35
37
36
- 1. From the list of known servers, the {+driver-short+} selects all servers
37
- that match the active read preference.
38
+ 1. Selects all servers that match the active read preference from the list of known servers.
38
39
39
- #. If at least one readable server exists, the {+ driver-short+} calls the user-defined
40
+ #. If at least one readable server exists, the driver calls the user-defined
40
41
server-selector function and passes in the list from the previous step.
41
42
42
- #. The {+driver-short+} applies the ``LocalThreshold`` connection setting to the list of
43
+ #. Applies the ``LocalThreshold`` connection setting to the list of
43
44
servers returned from the function.
44
45
45
- #. The {+driver-short+} selects a server at random from the servers still on the list and
46
+ #. Selects a server at random from the servers still on the list and
46
47
executes the operation against this server.
47
48
48
49
When the {+driver-short+} executes a write operation, it begins by selecting all writeable
49
50
servers, not just those that match the active read preference. The remaining steps are
50
51
identical.
51
52
52
- To learn more about the default server- selection algorithm, which the driver follows
53
- when you don't specify any custom server- selection logic, see
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
54
55
:manual:`Server Selection Algorithm </core/read-preference-mechanics/>` in the
55
- MongoDB Server manual.
56
+ {+mdb-server+} manual.
56
57
57
58
.. _csharp-server-selection-algorithm:
58
59
59
60
Specifying Other Server Selection Algorithms
60
61
--------------------------------------------
61
62
62
- You can specify different server- selection logic by passing an instance of a server selector
63
+ You can specify different server selection logic by passing an instance of a server selector
63
64
class to the ``PreServerSelector`` or ``PostServerSelector`` property of the ``ClusterConfigurator``. The
64
65
``PreServerSelector`` property specifies a server selector that runs before the
65
66
standard server selection logic runs, while the ``PostServerSelector`` property
66
67
specifies a server selector that runs after standard server selection logic runs. You can
67
68
then pass your ``ClusterConfigurator`` instance to the ``MongoClientSettings`` object when you create a
68
- ``MongoClient`` instance to apply your custom server- selection logic.
69
+ ``MongoClient`` instance to apply your custom server selection logic.
69
70
70
71
The following table lists the different types of server selectors you can pass to the
71
72
``ClusterConfigurator`` property:
72
73
73
74
.. list-table::
74
75
:header-rows: 1
75
- :widths: 30 70
76
+ :widths: 40 60
76
77
77
78
* - Server Selector
78
79
- Description
@@ -113,7 +114,7 @@ To learn more about the different server selector classes, see the
113
114
Implementing Custom Server Selection Logic
114
115
------------------------------------------
115
116
116
- You can also implement your own custom server- selection logic by creating a class that
117
+ You can implement your own custom server selection logic by creating a class that
117
118
inherits from the ``IServerSelector`` interface and overrides the
118
119
``SelectServers()`` method. The following example shows a simple custom server
119
120
selection class that selects servers with a ``ServerType`` of
@@ -153,7 +154,7 @@ in your connection URI:
153
154
154
155
* - ``ReadPreference``
155
156
- | The client's default read-preference settings. ``MaxStaleness`` represents the
156
- | longest replication lag (in wall-clock time) that a secondary can experience and
157
+ | longest replication lag (in real time) that a secondary can experience and
157
158
| still be eligible for server selection. Specifying ``-1`` means no maximum.
158
159
| See :ref:`read preference <read-preference>` for more information.
159
160
|
0 commit comments