Skip to content

Commit 264d478

Browse files
committed
DOCSP-47065: Load balancing
1 parent 09d6e1b commit 264d478

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

source/connect/connection-options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ Authentication Options
248248
To learn about the authentication options available in the {+driver-short+}, see
249249
:ref:`Authentication Mechanisms. <php-auth>`
250250

251+
.. _php-selection-discovery-options:
252+
251253
Server Selection and Discovery Options
252254
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253255

source/crud/read-write-pref.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ This section shows how to further customize your read operation
208208
settings 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,10 +241,42 @@ 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, 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+
244276
.. _php-local-threshold:
245277

246278
Local Threshold
247-
~~~~~~~~~~~~~~~
279+
```````````````
248280

249281
If multiple replica-set members match the read preference and tag sets you specify,
250282
the {+php-library+} reads from the nearest replica-set members, chosen according to

0 commit comments

Comments
 (0)