@@ -208,7 +208,7 @@ This section shows how to further customize your read operation
208
208
settings in the following ways:
209
209
210
210
- :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 >`
212
212
213
213
.. _php-tag-sets:
214
214
@@ -241,10 +241,42 @@ to prefer reads from secondary replica set members in the following order:
241
241
:start-after: start-tag-set
242
242
:end-before: end-tag-set
243
243
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, which avoids overwhelming
252
+ any one server and ensures 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
+
244
276
.. _php-local-threshold:
245
277
246
278
Local Threshold
247
- ~~~~~~~~~~~~~~~
279
+ ```````````````
248
280
249
281
If multiple replica-set members match the read preference and tag sets you specify,
250
282
the {+php-library+} reads from the nearest replica-set members, chosen according to
0 commit comments