您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

通过分区解决限制Partition around limits

使用分区来解决数据库、网络和计算限制Use partitioning to work around database, network, and compute limits

在云中,所有服务都有纵向扩展的限制。In the cloud, all services have limits in their ability to scale up. Azure 订阅和服务限制、配额和约束中介绍了 Azure 服务限制。Azure service limits are documented in Azure subscription and service limits, quotas, and constraints. 限制包括内核数、数据库大小、查询吞吐量和网络吞吐量。Limits include number of cores, database size, query throughput, and network throughput. 如果系统增长到足够大,可能会命中一个或多个限制。If your system grows sufficiently large, you may hit one or more of these limits. 使用分区来解决这些限制。Use partitioning to work around these limits.

有很多方法可用于分区系统,例如:There are many ways to partition a system, such as:

  • 分区数据库,以避免对数据库大小、数据 I/O 或并发会话数的限制。Partition a database to avoid limits on database size, data I/O, or number of concurrent sessions.

  • 分区队列或消息总线,以避免对请求数或并发连接数的限制。Partition a queue or message bus to avoid limits on the number of requests or the number of concurrent connections.

  • 分区应用服务 Web 应用,以避免对每个应用服务计划的实例数的限制。Partition an App Service web app to avoid limits on the number of instances per App Service plan.

可以水平、垂直、或按功能分区数据库。A database can be partitioned horizontally, vertically, or functionally.

  • 在水平分区(也称为分片)中,每个分区保存总数据集的子集的数据。In horizontal partitioning, also called sharding, each partition holds data for a subset of the total data set. 这些分区共享相同的数据架构。The partitions share the same data schema. 例如,名称以 A–M 开头的客户进入一个分区,以 N–Z 开头的进入另一个分区。For example, customers whose names start with A–M go into one partition, N–Z into another partition.

  • 在垂直分区中,每个分区保存数据存储中项字段的子集。In vertical partitioning, each partition holds a subset of the fields for the items in the data store. 例如,将经常访问的字段放在一个分区中,将较不经常访问的字段放在另一个分区。For example, put frequently accessed fields in one partition, and less frequently accessed fields in another.

  • 在功能分区中,根据系统中每个界限上下文使用数据的方式对数据进行分区。In functional partitioning, data is partitioned according to how it is used by each bounded context in the system. 例如,在一个分区中存储发票数据,在另一个分区中存储产品库存数据。For example, store invoice data in one partition and product inventory data in another. 架构是独立的。The schemas are independent.

有关更多详细指南,请参阅数据分区For more detailed guidance, see Data partitioning.

建议Recommendations

分区应用程序的不同部分Partition different parts of the application. 数据库显然很适合用于分区,但也需考虑存储、缓存、队列和计算实例。Databases are one obvious candidate for partitioning, but also consider storage, cache, queues, and compute instances.

设计分区键以避免产生热点Design the partition key to avoid hot spots. 如果分区数据库,但一个分片仍然获取大多数请求,那么问题还未解决。If you partition a database, but one shard still gets the majority of the requests, then you haven't solved your problem. 理想情况下,负载会在所有分区中均匀分布。Ideally, load gets distributed evenly across all the partitions. 例如,按客户 ID 而不是客户名称的首字母进行哈希分区,因为某些首字母会更集中。For example, hash by customer ID and not the first letter of the customer name, because some letters are more frequent. 分区消息队列时,该原则也同样适用。The same principle applies when partitioning a message queue. 选择一个可以在队列集中平均分布消息的分区键。Pick a partition key that leads to an even distribution of messages across the set of queues. 有关更多信息,请参阅分片For more information, see Sharding.

通过分区解决 Azure 订阅和服务限制Partition around Azure subscription and service limits. 单个组件和服务有限制,但订阅和资源组也有限制。Individual components and services have limits, but there are also limits for subscriptions and resource groups. 对于非常大的应用程序,可能需要进行分区来解决这些限制。For very large applications, you might need to partition around those limits.

在不同级别分区Partition at different levels. 请考虑部署在 VM 上的数据库服务器。Consider a database server deployed on a VM. VM 有一个由 Azure 存储支持的 VHD。The VM has a VHD that is backed by Azure Storage. 存储帐户属于 Azure 订阅。The storage account belongs to an Azure subscription. 请注意,层次结构中的每个步骤都有限制。Notice that each step in the hierarchy has limits. 数据库服务器可能有连接池限制。The database server may have a connection pool limit. VM 有 CPU 和网络限制。VMs have CPU and network limits. 存储有 IOPS 限制。Storage has IOPS limits. 订阅有 VM 内核数的限制。The subscription has limits on the number of VM cores. 一般来说,在较低的层次结构更容易分区。Generally, it's easier to partition lower in the hierarchy. 仅大型应用程序需要在订阅级别进行分区。Only large applications should need to partition at the subscription level.