Database Manual / Sharding / Data Partitioning / Moveable Collections

Multi-tenant Architecture with Moveable Collections具有可移动集合的多租户架构

New in version 8.0.在版本8.0中新增。

In a multi-tenant architecture, a single instance of an application serves multiple users. Multi-tenant users share resources, and generally data belonging to the same tenant is kept on a single shard.在多租户架构中,应用程序的单个实例为多个用户提供服务。多租户用户共享资源,通常属于同一租户的数据保存在单个分片上。

If your multi-tenant configuration has a single tenant per database and the majority of its workload takes place on a single shard, you can move frequently-accessed collections to other shards for more even workload distribution. This reduces the number of collections on the original shard and improves performance system-wide.如果多租户配置每个数据库只有一个租户,并且其大部分工作负载发生在单个分片上,则可以将频繁访问的集合移动到其他分片,以实现更均匀的工作负载分布。这减少了原始分片上的集合数量,并提高了整个系统的性能。

Note

Non-Sharded Clusters非分片化集群

If your multi-tenant deployment is a replica set, you can convert it to a sharded cluster and add additional shards to more evenly distribute your workload. For more information, see either:如果多租户部署是一个副本集,您可以将其转换为分片集群,并添加额外的分片以更均匀地分配工作负载。有关更多信息,请参阅:

Considerations注意事项

  • Moving collections has operational overhead. Before you move collections, review the sh.moveCollection() documentation for performance considerations.移动集合会产生运营开销。在移动集合之前,请查看sh.moveCollection()文档以了解性能考虑因素。
  • The optimal multi-tenant configuration depends on your workload and application needs. Moving collections to new shards is not as scalable as multi-tenancy in a single database with shared collections. 最佳的多租户配置取决于工作负载和应用程序需求。将集合移动到新的分片并不像具有共享集合的单个数据库中的多租户那样可扩展。However, having each database correspond to a single tenant allows for more customizable security and access patterns.然而,让每个数据库对应一个租户,可以实现更可定制的安全性和访问模式。
  • To optimize performance for cross-collection operations (like $lookup or transactions that access multiple collections), place all collections for a given tenant on the same shard.为了优化跨集合操作(如$lookup或访问多个集合的事务)的性能,请将给定租户的所有集合放置在同一分片上。

Learn More了解更多