On this page本页内容
A MongoDB sharded cluster consists of the following components:
mongos
acts as a query router, providing an interface between client applications and the sharded cluster. Starting in MongoDB 4.4, mongos
can support hedged reads to minimize latencies.In a production cluster, ensure that data is redundant and that your systems are highly available. Consider the following for a production sharded cluster deployment:
mongos
routersWhere possible, consider deploying one member of each replica set in a site suitable for being a disaster recovery location.
Note
Distributing replica set members across two data centers provides benefit over a single data center. In a two data center distribution,
If possible, distribute members across at least three data centers. For config server replica sets (CSRS), the best practice is to distribute across three (or more depending on the number of members) centers. If the cost of the third data center is prohibitive, one distribution possibility is to evenly distribute the data bearing members across the two data centers and store the remaining member in the cloud if your company policy allows.
Sharding requires at least two shards to distribute sharded data. Single shard sharded clusters may be useful if you plan on enabling sharding in the near future, but do not need to at the time of deployment.
mongos
and Distribution¶Deploying multiple mongos
routers supports high availability and scalability. A common pattern is to place a mongos
on each application server. Deploying one mongos
router on each application server reduces network latency between the application and the router.
Alternatively, you can place a mongos
router on dedicated hosts. Large deployments benefit from this approach because it decouples the number of client application servers from the number of mongos
instances. This gives greater control over the number of connections the mongod
instances serve.
Installing mongos
instances on their own hosts allows these instances to use greater amounts of memory. Memory would not be shared with a mongod
instance. It is possible to use primary shards to host mongos
routers but be aware that memory contention may become an issue on large deployments.
There is no limit to the number of mongos
routers you can have in a deployment. However, as mongos
routers communicate frequently with your config servers, monitor config server performance closely as you increase the number of routers. If you see performance degradation, it may be beneficial to cap the number of mongos
routers in your deployment.
For testing and development, you can deploy a sharded cluster with a minimum number of components. These non-production clusters have the following components:
mongos
instance.Warning
Use the test cluster architecture for testing and development only.
See also参阅