Database Manual / Sharding / Administration

Scaling Strategies扩展策略

Database scaling is a fundamental challenge for growing applications. Whether you start a new application or experience growth, there are two main scaling strategies:数据库扩展是不断增长的应用程序面临的一个基本挑战。无论您是启动新应用程序还是体验增长,都有两种主要的扩展策略:

While vertical scaling can provide immediate relief to resource allocation, horizontal scaling is a more sustainable and flexible approach when scale is a factor.虽然垂直缩放可以立即缓解资源分配,但当规模是一个因素时,水平缩放是一种更可持续和更灵活的方法。

As applications grow, traditional database scaling forces difficult trade-offs between performance, complexity, and cost. 随着应用程序的增长,传统的数据库扩展迫使在性能、复杂性和成本之间进行艰难的权衡。MongoDB supports horizontal scaling through its sharding architecture, which distributes data and workloads across multiple servers known as shards. MongoDB通过其分片架构支持水平扩展,该架构将数据和工作负载分布在多个称为分片的服务器上。If you’re building for scale, it’s crucial to consider sharding proactively to ensure seamless growth.如果你正在为规模而构建,那么主动考虑分片以确保无缝增长至关重要。

MongoDB's sharded cluster architecture offers several strategies to scale your database:MongoDB的分片集群架构提供了几种扩展数据库的策略:

You can use these flexible scaling capabilities to optimize performance and control costs, while maintaining a single connection point for your applications.您可以使用这些灵活的扩展功能来优化性能和控制成本,同时为应用程序维护一个连接点。

Strategies for Horizontal Scaling水平缩放策略

In a sharded cluster, each shard is a replica set. Multiple shards function as a part of the same cluster. Your application accesses all resources transparently by connecting to mongos, which handles the complexity of routing requests to the right place.在分片集群中,每个分片都是一个副本集。多个分片作为同一集群的一部分。应用程序通过连接到mongos透明地访问所有资源,mongos处理将请求路由到正确位置的复杂性。

There are two primary methods to distribute workloads in a sharded cluster:在分片集群中分配工作负载有两种主要方法:

  • Moving collections onto dedicated shards – Assign entire collections to specific shards, optimizing performance by distributing workloads strategically.将集合移动到专用分片上-将整个集合分配给特定的分片,通过战略性地分配工作负载来优化性能。
  • Partitioning a collection across multiple shards – Split a single collection across multiple shards using a shard key, distributing data more evenly for scalability.跨多个分片分割一个集合-使用分片键将单个集合跨多个分片分割,更均匀地分配数据以实现可扩展性。

These approaches can be used independently or combined, depending on your requirements.根据要求,这些方法可以单独使用或组合使用。

Getting Started入门指南

Start with Sharded Clusters从分片集群开始
Learn the benefits of starting with a single shard when building your application.了解在构建应用程序时从单个分片开始的好处。
Manage Unsharded Collections管理未硬化的集合
Learn about isolating collections on dedicated shards.了解如何在专用分片上隔离集合。
Distribute Collection Data分发集合数据
Learn about sharding a collection.了解如何对集合进行分片。
Consolidate Collection Data整合集合数据
Learn about unsharding a collection.了解如何取消集合。