Skip to content

Commit bd9be88

Browse files
committed
tech review 2
1 parent f7a237a commit bd9be88

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

source/crud/read-write-config.txt

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -214,30 +214,6 @@ The following example shows how to connect to a sharded cluster and specify a
214214
:start-after: start-sharded-cluster-uri
215215
:end-before: end-sharded-cluster-uri
216216

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-
241217
.. _java-tag-sets:
242218

243219
Tag Sets
@@ -271,23 +247,61 @@ to set the read order on the database:
271247
:start-after: start-tag-set
272248
:end-before: end-tag-set
273249

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+
274280
.. _java-local-threshold:
275281

276282
Local Threshold
277-
~~~~~~~~~~~~~~~
283+
```````````````
278284

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.
282288

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.
287294

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:
291305

292306
.. tabs::
293307

@@ -313,13 +327,6 @@ corresponding code for each approach:
313327
In the preceding example, the {+driver-short+} distributes reads among matching members
314328
within 35 milliseconds of the closest member's ping time.
315329

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-
323330
API Documentation
324331
-----------------
325332

0 commit comments

Comments
 (0)