@@ -214,30 +214,6 @@ The following example shows how to connect to a sharded cluster and specify a
214
214
:start-after: start-sharded-cluster-uri
215
215
:end-before: end-sharded-cluster-uri
216
216
217
- Load Balancing
218
- ``````````````
219
-
220
- If there is more than one mongos instance in the connection seed list, the
221
- {+driver-short+} uses **load balancing**. Load balancing allows the driver to
222
- distribute read and write requests across multiple servers, which avoids overwhelming
223
- one server in the sharded cluster and ensures optimal performance.
224
-
225
- To distribute database requests, the {+driver-short+} determines the closest mongos
226
- by calculating which one has the lowest network round-trip time. Then, the driver
227
- determines the latency window by adding this mongos's average round-trip time to the
228
- :ref:`localThresholdMS value <java-local-threshold>`. The driver load balances requests
229
- across up to two mongos instances that fall within the latency window. For each request,
230
- the driver chooses the server with the lower operation load by determining its ``operationCount``
231
- value.
232
-
233
- .. tip::
234
-
235
- To learn more about load balancing, see :manual:`Sharded Cluster Balancer
236
- </core/sharding-balancer-administration/>` in the {+mdb-server+} manual.
237
-
238
- To learn how to customize the driver's server selection behavior, see
239
- :ref:`mcs-cluster-settings` in the Specify MongoClient Settings guide.
240
-
241
217
.. _java-tag-sets:
242
218
243
219
Tag Sets
@@ -271,23 +247,61 @@ to set the read order on the database:
271
247
:start-after: start-tag-set
272
248
:end-before: end-tag-set
273
249
250
+ Load Balancing
251
+ ~~~~~~~~~~~~~~
252
+
253
+ When connecting to a sharded cluster or a replica set, the {+driver-short+} uses
254
+ **load balancing** to handle read and write requests. Load balancing allows the driver to
255
+ distribute these requests across multiple servers, which avoids overwhelming
256
+ any one server and ensures optimal performance.
257
+
258
+ When connecting to a sharded cluster, the {+driver-short+} determines the closest mongos
259
+ instance by calculating which one has the lowest network round-trip time. Then, the driver
260
+ determines the latency window by adding this mongos's average round-trip time to the
261
+ :ref:`localThresholdMS value <java-local-threshold>`. The driver load balances requests
262
+ across up to two random mongos instances that fall within the latency window. For each request,
263
+ the driver chooses the server with the lower operation load by determining its ``operationCount``
264
+ value.
265
+
266
+ When connecting to a replica set, the {+driver-short+} first selects replica set members
267
+ according to your read preference. Then, the driver follows the same process as
268
+ described in the preceding paragraph. After calculating the latency window, the driver
269
+ selects up to two random replica set members that fall within the window and chooses
270
+ the member with the lower ``operationCount`` value to receive the request.
271
+
272
+ .. tip::
273
+
274
+ To learn more about load balancing, see :manual:`Sharded Cluster Balancer
275
+ </core/sharding-balancer-administration/>` in the {+mdb-server+} manual.
276
+
277
+ To learn how to customize the driver's server selection behavior, see
278
+ :ref:`mcs-cluster-settings` in the Specify MongoClient Settings guide.
279
+
274
280
.. _java-local-threshold:
275
281
276
282
Local Threshold
277
- ~~~~~~~~~~~~~~~
283
+ ```````````````
278
284
279
- If multiple replica set members match the read preference and tag sets that you specify,
280
- the {+driver-short+} reads from the nearest replica set members, chosen according to
281
- their ping time .
285
+ The {+driver-short+} uses the local threshold value to calculate the
286
+ latency window for server selection. This value determines the servers
287
+ that are eligible to receive read and write requests .
282
288
283
- By default, the driver uses only members whose ping times are within 15 milliseconds
284
- of the nearest member for queries. To distribute reads among members with
285
- higher latencies, set the ``localThreshold`` option in a ``MongoClientSettings``
286
- instance or the ``localThresholdMS`` option in your connection URI.
289
+ By default, the driver uses only mongos instances or replica set members whose
290
+ ping times are within 15 milliseconds of the nearest server. To
291
+ distribute reads among servers with higher latencies, set the ``localThreshold``
292
+ option in a ``MongoClientSettings`` instance or the ``localThresholdMS`` option
293
+ in your connection URI.
287
294
288
- The following example specifies a local threshold of 35 milliseconds. Select
289
- the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI` tab to see
290
- corresponding code for each approach:
295
+ .. note::
296
+
297
+ When communicating with a mongos instance, the {+driver-short+} ignores the
298
+ ``localThresholdMS`` URI option. In this case, use the
299
+ :manual:`localThreshold </reference/program/mongos/#std-option-mongos.--localThreshold>`
300
+ command-line option.
301
+
302
+ The following example connects to a replica set and specifies a local threshold
303
+ of 35 milliseconds. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
304
+ tab to see corresponding code for each approach:
291
305
292
306
.. tabs::
293
307
@@ -313,13 +327,6 @@ corresponding code for each approach:
313
327
In the preceding example, the {+driver-short+} distributes reads among matching members
314
328
within 35 milliseconds of the closest member's ping time.
315
329
316
- .. note::
317
-
318
- The {+driver-short+} ignores the ``localThresholdMS`` option when communicating with a
319
- replica set through a ``mongos`` instance. In this case, use the
320
- :manual:`localThreshold </reference/program/mongos/#std-option-mongos.--localThreshold>`
321
- command-line option.
322
-
323
330
API Documentation
324
331
-----------------
325
332
0 commit comments