@@ -208,7 +208,7 @@ This section shows how to further customize your read operation
208208settings in the following ways:
209209
210210- :ref:`Apply a tag set <php-tag-sets>`
211- - :ref:`Specify a local threshold <php-local-threshold >`
211+ - :ref:`Configure load balancing behavior <php-load-balancing >`
212212
213213.. _php-tag-sets:
214214
@@ -241,19 +241,51 @@ to prefer reads from secondary replica set members in the following order:
241241 :start-after: start-tag-set
242242 :end-before: end-tag-set
243243
244+ .. _php-load-balancing:
245+
246+ Load Balancing
247+ ~~~~~~~~~~~~~~
248+
249+ When connecting to a sharded cluster or a replica set, the {+library-short+} uses
250+ **load balancing** to handle read and write requests. Load balancing allows the library to
251+ distribute these requests across multiple servers to avoid overwhelming
252+ any one server and ensure optimal performance.
253+
254+ When connecting to a sharded cluster, the {+library-short+} determines the closest ``mongos``
255+ instance by calculating which one has the lowest network round-trip time. Then, the library
256+ determines the latency window by adding this ``mongos``'s average round-trip time to the
257+ :ref:`localThresholdMS value <php-local-threshold>`. The library load balances requests
258+ across up to two random ``mongos`` instances that fall within the latency window. For each request,
259+ the library chooses the server with the lower operation load by determining its ``operationCount``
260+ value.
261+
262+ When connecting to a replica set, the {+library-short+} first selects replica set members
263+ according to your read preference. Then, the library follows the same process as
264+ described in the preceding paragraph. After calculating the latency window, the library
265+ selects up to two random replica set members that fall within the window and chooses
266+ the member with the lower ``operationCount`` value to receive the request.
267+
268+ .. tip::
269+
270+ To learn more about load balancing, see :manual:`Sharded Cluster Balancer
271+ </core/sharding-balancer-administration/>` in the {+mdb-server+} manual.
272+
273+ To learn how to customize the library's server selection behavior, see
274+ :ref:`php-selection-discovery-options` in the Specify Connection Options guide.
275+
244276.. _php-local-threshold:
245277
246278Local Threshold
247- ~~~~~~~~~~~~~~~
279+ ```````````````
248280
249- If multiple replica-set members match the read preference and tag sets you specify,
250- the {+php-library+} reads from the nearest replica-set members, chosen according to
251- their ping time .
281+ The {+library-short+} uses the local threshold value to calculate the
282+ latency window for server selection. This value determines the servers
283+ that are eligible to receive read and write requests .
252284
253- By default, the library uses only members whose ping times are within 15 milliseconds
254- of the nearest member for queries. To distribute reads between members with
255- higher latencies, pass an options array to the ``MongoDB\Client`` constructor that
256- sets the ``localThresholdMS`` option.
285+ By default, the library uses only ``mongos`` instances or replica set members whose
286+ ping times are within 15 milliseconds of the nearest server. To
287+ distribute reads among servers with higher latencies, pass an options array to
288+ the ``MongoDB\Client`` constructor that sets the ``localThresholdMS`` option.
257289
258290The following example specifies a local threshold of 35 milliseconds:
259291
0 commit comments