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

为 Azure 搜索中的查询和索引工作负载分配分区和副本Allocate partitions and replicas for query and indexing workloads in Azure Search

选择定价层预配搜索服务后,下一步是有选择性地增加服务使用的副本或分区数目。After you choose a pricing tier and provision a search service, the next step is to optionally increase the number of replicas or partitions used by your service. 每一层提供固定数量的计费单位。Each tier offers a fixed number of billing units. 本文介绍如何通过分配这些单位来实现最佳配置,根据查询执行、索引和存储的要求做出平衡。This article explains how to allocate those units to achieve an optimal configuration that balances your requirements for query execution, indexing, and storage.

基本层或某个标准层中设置服务时,可以使用资源配置。Resource configuration is available when you set up a service at the Basic tier or one of the Standard tiers. 对于这些层中的服务,购买的容量以搜索单位 (SU) 为增量,其中每个分区和副本被视为一个 SU。For services at these tiers, capacity is purchased in increments of search units (SUs) where each partition and replica counts as one SU.

使用的 SU 越少,帐单费用也就相应地越少。Using fewer SUs results in a proportionally lower bill. 只要设置服务,就会产生费用。Billing is in effect for as long as the service is set up. 如果暂时不使用某个服务,避免计费的唯一方法就是删除该服务,需要该服务时再重新创建。If you are temporarily not using a service, the only way to avoid billing is by deleting the service and then re-creating it when you need it.

备注

删除某个服务会删除该服务上的所有内容。Deleting a service deletes everything on it. Azure 搜索中没有用于备份和还原持久化搜索数据的设施。There is no facility within Azure Search for backing up and restoring persisted search data. 若要在新服务上重新部署现有索引,应当运行最初用来创建和加载该索引的程序。To redeploy an existing index on a new service, you should run the program used to create and load it originally.

术语:分区和副本Terminology: partitions and replicas

分区和副本是支持搜索服务的主要资源。Partitions and replicas are the primary resources that back a search service.

资源Resource 定义Definition
分区Partitions 为读/写操作(例如在重建或刷新索引时)提供索引存储和 I/O。Provides index storage and I/O for read/write operations (for example, when rebuilding or refreshing an index).
副本Replicas 是搜索服务的实例,主要用于对查询操作进行负载均衡。Instances of the search service, used primarily to load balance query operations. 每个副本始终托管索引的一个副本。Each replica always hosts one copy of an index. 如果有 12 个副本,服务中会加载每个索引的 12 个副本。If you have 12 replicas, you will have 12 copies of every index loaded on the service.

备注

无法直接操作或管理哪些索引在副本上运行。There is no way to directly manipulate or manage which indexes run on a replica. 每个副本托管索引的一个副本,这是服务体系结构的一部分。One copy of each index on every replica is part of the service architecture.

如何分配分区和副本How to allocate partitions and replicas

在 Azure 搜索中,最初为服务分配了由一个分区和一个副本组成的最低级别的资源。In Azure Search, a service is initially allocated a minimal level of resources consisting of one partition and one replica. 如果层支持这样做,可以递增方式调整计算资源:需要更多的存储和 I/O 时增加分区,或者增加副本来应对较大的查询卷或提供较好的性能。For tiers that support it, you can incrementally adjust computational resources by increasing partitions if you need more storage and I/O, or add more replicas for larger query volumes or better performance. 单个服务必须具有足够的资源才能处理所有工作负荷(索引和查询)。A single service must have sufficient resources to handle all workloads (indexing and queries). 无法在多个服务之间细分工作负荷。You cannot subdivide workloads among multiple services.

若要增加或更改副本和分区的分配,建议使用 Azure 门户。To increase or change the allocation of replicas and partitions, we recommend using the Azure portal. 该门户针对允许的组合强制实施限制,使其低于上限:The portal enforces limits on allowable combinations that stay below maximum limits:

  1. 登录到 Azure 门户,并选择搜索服务。Sign in to the Azure portal and select the search service.
  2. 在“设置”中打开“缩放”边栏选项卡,并使用滑块来增加或减少分区和副本数目。In Settings, open the Scale blade and use the sliders to increase or decrease the number of partitions and replicas.

如果需要使用基于脚本或基于代码的预配方法,可以改用管理 REST APIIf you require a script-based or code-based provisioning approach, the Management REST API is an alternative to the portal.

一般而言,搜索应用程序所需的副本数多过分区数,尤其是在服务操作偏向于查询工作负荷的情况下。Generally, search applications need more replicas than partitions, particularly when the service operations are biased toward query workloads. 高可用性部分将解释原因。The section on high availability explains why.

备注

预配服务后,无法升级到更高的 SKU。After a service is provisioned, it cannot be upgraded to a higher SKU. 必须在新层中创建搜索服务,并重新加载索引。You must create a search service at the new tier and reload your indexes. 有关服务预配的帮助,请参阅 Create an Azure Search service in the portal(在门户中创建 Azure 搜索服务)。See Create an Azure Search service in the portal for help with service provisioning.

高可用性High availability

由于扩展的过程比较简单而且相对较快,因此我们通常建议从一个分区以及一个或两个副本开始,并随着不断构建查询卷而进行扩展。Because it's easy and relatively fast to scale up, we generally recommend that you start with one partition and one or two replicas, and then scale up as query volumes build. 查询工作负荷主要是在副本上运行。Query workloads run primarily on replicas. 如果需要更高的吞吐量或高可用性,也许需要增加副本。If you need more throughput or high availability, you will probably require additional replicas.

针对高可用性的一般建议是:General recommendations for high availability are:

  • 对于只读工作负荷(查询),需要有两个副本才能实现高可用性Two replicas for high availability of read-only workloads (queries)
  • 对于读/写工作负荷(查询以及添加、更新或删除单个文档时的索引编制),需有三个或更多个副本才能实现高可用性Three or more replicas for high availability of read/write workloads (queries plus indexing as individual documents are added, updated, or deleted)

Azure 搜索的服务级别协议 (SLA) 针对查询操作,以及由文档添加、更新或删除操作构成的索引更新。Service level agreements (SLA) for Azure Search are targeted at query operations and at index updates that consist of adding, updating, or deleting documents.

基本层最多能有一个分区和三个副本。Basic tier tops out at one partition and three replicas. 如果希望灵活地立即响应对索引编制和查询吞吐量的需求波动,请考虑使用标准层中的一个。If you want the flexibility to immediately respond to fluctuations in demand for both indexing and query throughput, consider one of the Standard tiers.

重建期间的索引可用性Index availability during a rebuild

Azure 搜索的高可用性与查询以及不涉及重建索引的索引更新相关。High availability for Azure Search pertains to queries and index updates that don't involve rebuilding an index. 如果删除字段、更改数据类型或重命名字段,则需要重建索引。If you delete a field, change a data type, or rename a field, you will need to rebuild the index. 要重建索引,必须删除该索引,重新创建该索引,并重新加载数据。To rebuild the index, you must delete the index, re-create the index, and reload the data.

备注

可将新字段添加到 Azure 搜索索引,而无需重建索引。You can add new fields to an Azure Search index without rebuilding the index. 对于索引中已存在的所有文档,新字段的值将为 null。The value of the new field will be null for all documents already in the index.

要让索引在重建期间保持可用,相同的服务中必须存在不同名的索引副本,或者不同的服务中存在同名的索引,并在代码中提供重定向或故障转移逻辑。To maintain index availability during a rebuild, you must have a copy of the index with a different name on the same service, or a copy of the index with the same name on a different service, and then provide redirection or failover logic in your code.

灾难恢复Disaster recovery

目前没有任何内置的机制可实现灾难恢复。Currently, there is no built-in mechanism for disaster recovery. 添加分区或副本并不是实现灾难恢复目标的正确策略。Adding partitions or replicas would be the wrong strategy for meeting disaster recovery objectives. 最常见的方法是通过在另一区域中设置另一个搜索服务,在服务级别添加冗余。The most common approach is to add redundancy at the service level by setting up a second search service in another region. 与索引重建期间的可用性一样,重定向或故障转移逻辑必须来自代码。As with availability during an index rebuild, the redirection or failover logic must come from your code.

使用副本提高查询性能Increase query performance with replicas

如果出现查询延迟,则表明需要增加副本。Query latency is an indicator that additional replicas are needed. 一般而言,改善查询性能的第一步是增加此类资源。Generally, a first step toward improving query performance is to add more of this resource. 添加副本时,将有更多的索引副本联机,可支持更大的查询工作负荷,通过多个副本对请求进行负载均衡。As you add replicas, additional copies of the index are brought online to support bigger query workloads and to load balance the requests over the multiple replicas.

我们无法提供可靠的每秒查询数 (QPS) 预测:查询性能取决于查询和竞争工作负荷的复杂性。We cannot provide hard estimates on queries per second (QPS): query performance depends on the complexity of the query and competing workloads. 尽管添加副本会明显提高性能,但结果不一定有线性改善:添加三个副本并不保证带来三倍的吞吐量。Although adding replicas clearly results in better performance, the result is not strictly linear: adding three replicas does not guarantee triple throughput.

有关估计工作负荷的 QPS 的指南,请参阅 Azure 搜索的性能和优化注意事项For guidance in estimating QPS for your workloads, see Azure Search performance and optimization considerations.

使用分区提高索引性能Increase indexing performance with partitions

需要以近乎实时的速度刷新数据的搜索应用程序,需要的分区数在比例上要多于副本。Search applications that require near real-time data refresh will need proportionally more partitions than replicas. 添加分区可将读/写操作分配到更多的计算资源。Adding partitions spreads read/write operations across a larger number of compute resources. 此外,还能提供更多磁盘空间来存储更多的索引和文档。It also gives you more disk space for storing additional indexes and documents.

索引越大,查询所需的时间就越长。Larger indexes take longer to query. 因此,可能发现,每次增加分区都需要按比例少量增加副本。As such, you might find that every incremental increase in partitions requires a smaller but proportional increase in replicas. 查询和查询卷的复杂性影响查询执行的速度。The complexity of your queries and query volume will factor into how quickly query execution is turned around.

基本层:分区和副本组合Basic tier: Partition and replica combinations

“基本”服务可以包含一个分区以及最多三个副本,上限为三个 SU。A Basic service can have exactly one partition and up to three replicas, for a maximum limit of three SUs. 唯一可调整的资源是副本。The only adjustable resource is replicas. 至少需要两个副本才能实现查询的高可用性。You need a minimum of two replicas for high availability on queries.

标准层:分区和副本组合Standard tiers: Partition and replica combinations

下表显示了支持副本和分区组合所需的搜索单位数,所有标准层限制为 36 个 SU。This table shows the SUs required to support combinations of replicas and partitions, subject to the 36-SU limit, for all Standard tiers.

1 个分区1 partition 2 个分区2 partitions 3 个分区3 partitions 4 个分区4 partitions 6 个分区6 partitions 12 个分区12 partitions
1 个副本1 replica 1 个 SU1 SU 2 SU2 SU 3 SU3 SU 4 SU4 SU 6 SU6 SU 12 SU12 SU
2 个副本2 replicas 2 SU2 SU 4 SU4 SU 6 SU6 SU 8 SU8 SU 12 SU12 SU 24 SU24 SU
3 个副本3 replicas 3 SU3 SU 6 SU6 SU 9 SU9 SU 12 SU12 SU 18 SU18 SU 36 个 SU36 SU
4 个副本4 replicas 4 SU4 SU 8 SU8 SU 12 SU12 SU 16 SU16 SU 24 SU24 SU 不适用N/A
5 副本5 replicas 5 SU5 SU 10 SU10 SU 15 SU15 SU 20 SU20 SU 30 SU30 SU 不适用N/A
6 个副本6 replicas 6 SU6 SU 12 SU12 SU 18 SU18 SU 24 SU24 SU 36 个 SU36 SU 不适用N/A
12 副本12 replicas 12 SU12 SU 24 SU24 SU 36 个 SU36 SU 不适用N/A 不适用N/A 不适用N/A

Azure 网站上详细说明了 SU、定价和容量。SUs, pricing, and capacity are explained in detail on the Azure website. 有关详细信息,请参阅 Pricing Details(定价详细信息)。For more information, see Pricing Details.

备注

副本数和分区数必须能被 12 整除(具体而言,为 1、2、3、4、6、12)。The number of replicas and partitions divides evenly into 12 (specifically, 1, 2, 3, 4, 6, 12). 这是因为,Azure 搜索将每个索引预先分割为 12 个分片,以便将其平均分散到所有分区。This is because Azure Search pre-divides each index into 12 shards so that it can be spread in equal portions across all partitions. 例如,如果服务有三个分区,而你创建了新索引,则每个分区将包含该索引的四个分片。For example, if your service has three partitions and you create an index, each partition will contain four shards of the index. Azure 搜索为索引分片的方法属于实现细节,在将来的版本中可能发生变化。How Azure Search shards an index is an implementation detail, subject to change in future releases. 尽管目前的分区数为 12,但请不要料想将来该数字永远都是 12。Although the number is 12 today, you shouldn't expect that number to always be 12 in the future.

副本和分区资源的计费公式Billing formula for replica and partition resources

计算特定组合所用 SU 数的公式为副本数乘以分区数的积,即 (R X P = SU)。The formula for calculating how many SUs are used for specific combinations is the product of replicas and partitions, or (R X P = SU). 例如,3 个副本乘以 3 个分区,按 9 个 SU 计费。For example, three replicas multiplied by three partitions is billed as nine SUs.

每个 SU 的成本由层决定。基本层的每个 SU 成本低于标准层。Cost per SU is determined by the tier, with a lower per-unit billing rate for Basic than for Standard. 有关每层的费率,请参阅 Pricing Details(定价详细信息)。Rates for each tier can be found on Pricing Details.