6.5. Gear Placement Algorithm
Prerequisites:
MongoDB configures district capacity. Gear status does not affect district capacity, because districts reserve resources; they do not account for actual usage. In the JSON record for a district, max_capacity
indicates the maximum number of gears that can be placed in the district, while available_capacity
indicates the number of gears still available in that district. See Section 6.3.3, “Viewing District Information” for details on viewing the JSON record of a district.
When choosing nodes for new gears, the default gear placement algorithm also considers any least preferred servers and restricted servers to help maintain high availability for applications. Least preferred servers are nodes that already have gears on them for the given application gear group; it is preferable to find other nodes instead so that high availability is ensured. Restricted servers are nodes that should not be chosen at all. For example, restricted servers would be identified for high-availability applications when two HAProxy gears are created to ensure they are placed on different nodes.
The following steps describe the default algorithm for selecting a node on which to place a new gear for an application:
- Find all the districts.
- Find the nodes that have the least
active_capacity
. - Filter nodes based on given criteria to ensure gears within scalable applications are spread across multiple nodes.
- Filter non-districted nodes when districts are required.
- When regions and zones are present:
- Filter nodes without zones when zones are required.
- If the application already has gears on a node tagged with a region, exclude nodes that do not belong to the current region.
- Verify whether the minimum required number of zones for application gear groups is met.
- Filter zones to ensure that gears within the application gear group do not exist solely in a single zone.
- Choose zones that are least consumed to evenly distribute gears among zones.
- When zone nodes available, exclude nodes without zones.
- When districted nodes are available, exclude nodes without districts.
- Among remaining nodes, choose the ones with plenty of available capacity that are in districts with available UIDs.
- Randomly choose one of the nodes with the lower levels of
active_capacity
.