0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-25 09:19:32 +01:00
mongodb/docs/load_balancer_support.md
Alex Neben b665258d9d SERVER-88970 Added yaml formatting to server repo
GitOrigin-RevId: 35db3811d8f749edd5b79ba910adcbc1ceb54cc4
2024-04-06 05:23:20 +00:00

2.5 KiB

Load balancer support

mongos has built-in support for connections made via L4 load balancers. However, placing mongos endpoints behind load balancers requires proper configuration of the load balancers, mongos, and any drivers or shells used to connect to the database. Three conditions must be fulfilled for mongos to be used behind a load balancer:

  • mongos must be configured with the MongoDB Server Parameter loadBalancerPort whose value can be specified at program start in any of the ways mentioned in the server parameter documentation. This option causes mongos to open a second port that expects only load balanced connections. All connections made from load balancers must be made over this port, and no regular connections may be made over this port.
  • The L4 load balancer must be configured to emit a proxy protocol header at the start of its connection stream. mongos supports both version 1 and version 2 of the proxy protocol standard.
  • The connection string used to establish the mongos connection must set the loadBalanced option, e.g., when connecting to a local mongos instance, if the loadBalancerPort server parameter was set to 20100, the connection string must be of the form "mongodb://localhost:20100/?loadBalanced=true".

mongos will emit appropiate error messages on connection attempts if these requirements are not met.

There are some subtle behavioral differences that these configuration options enable, chief of which is how mongos deals with open cursors on client disconnection. Over a normal connection, mongos will keep open cursors alive for a short while after client disconnection in case the client reconnects and continues to request more from the given cursor. Since client reconnections aren't expected behind a load balancer (as the load balancer will likely redirect a given client to a different mongos instance upon reconnection), we eagerly close cursors on load balanced client disconnects. We also abort any in-progress transactions that were initiated by the load balanced client.