Azure Functions 高级计划Azure Functions Premium plan

Azure Functions 高级计划(有时称为“弹性高级计划”)是函数应用的一个托管选项。The Azure Functions Premium plan (sometimes referred to as Elastic Premium plan) is a hosting option for function apps. 有关其他托管计划选项,请参阅托管计划文章For other hosting plan options, see the hosting plan article.

高级计划托管为函数提供了以下好处:Premium plan hosting provides the following benefits to your functions:

  • 使用永久温实例避免冷启动Avoid cold starts with perpetually warm instances
  • 虚拟网络连接。Virtual network connectivity.
  • 无限制的执行持续时间(保证 60 分钟)。Unlimited execution duration, with 60 minutes guaranteed.
  • 高级实例大小:单核心、双核心和四核心实例。Premium instance sizes: one core, two core, and four core instances.
  • 与消耗计划相比,定价可预测性更高。More predictable pricing, compared with the Consumption plan.
  • 对于具有多个函数应用的计划,提供了高密度应用分配。High-density app allocation for plans with multiple function apps.

就像消耗计划一样,使用高级计划时,会根据传入事件数添加和删除 Azure Functions 主机实例。When you're using the Premium plan, instances of the Azure Functions host are added and removed based on the number of incoming events, just like the Consumption plan. 可以将多个函数应用部署到同一高级计划,该计划允许配置计算实例大小、基本计划大小和最大计划大小。Multiple function apps can be deployed to the same Premium plan, and the plan allows you to configure compute instance size, base plan size, and maximum plan size.

计费Billing

高级计划的计费基于跨实例分配的核心秒数和内存。Billing for the Premium plan is based on the number of core seconds and memory allocated across instances. 此计费不同于消耗计划,后者按执行和消耗的内存计费。This billing differs from the Consumption plan, which is billed per execution and memory consumed. 高级计划不收取执行费用。There is no execution charge with the Premium plan. 每个计划必须始终至少分配一个实例。At least one instance must be allocated at all times per plan. 使用此计费方式,无论函数是活动的还是空闲的,每个活动计划的月成本都是最低的。This billing results in a minimum monthly cost per active plan, regardless if the function is active or idle. 请记住,高级计划中的所有函数应用会共享已分配的实例。Keep in mind that all function apps in a Premium plan share allocated instances. 若要了解详细信息,请参阅 Azure Functions 定价页To learn more, see the Azure Functions pricing page.

创建高级计划Create a Premium plan

在 Azure 门户中创建函数应用时,消耗计划为默认值。When you create a function app in the Azure portal, the Consumption plan is the default. 若要创建在高级计划中运行的函数应用,必须使用弹性高级 SKU 之一显式创建应用服务计划。To create a function app that runs in a Premium plan, you must explicitly create an App Service plan using one of the Elastic Premium SKUs. 然后,在此计划中托管你创建的函数应用。The function app you create is then hosted in this plan. 可以使用 Azure 门户轻松地同时创建高级计划和函数应用。The Azure portal makes it easy to create both the Premium plan and the function app at the same time. 可以在同一高级计划中运行多个函数应用,但它们必须在相同的操作系统(Windows 或 Linux)上运行。You can run more than one function app in the same Premium plan, but they most both run on the same operating system (Windows or Linux).

以下文章说明了如何通过编程方式或 Azure 门户创建采用高级计划的函数应用:The following articles show you how to create a function app with a Premium plan, either programmatically or in the Azure portal:

消除冷启动Eliminate cold starts

当消耗计划中没有发生任何事件或执行任何操作时,你的应用可以缩减到零个实例。When events or executions don't occur in the Consumption plan, your app may scale to zero instances. 当出现新事件时,必须使运行应用的新实例专用化。When new events come in, a new instance with your app running on it must be specialized. 将新实例专用化可能需要一些时间,具体取决于应用。Specializing new instances may take some time depending on the app. 第一次调用时的这种额外延迟通常称为应用冷启动。This additional latency on the first call is often called app cold start.

高级计划提供了两个功能,这些功能协同工作以有效地消除函数中的冷启动:“始终就绪实例”和“预热实例”。Premium plan provides two features that work together to effectively eliminate cold starts in your functions: always ready instances and pre-warmed instances.

始终就绪实例Always ready instances

在高级计划中,你可以让应用在指定数量的实例上始终处于就绪状态。In the Premium plan, you can have your app always ready on a specified number of instances. 始终就绪实例的最大数目为 20。The maximum number of always ready instances is 20. 当事件开始触发应用时,它们首先路由到始终就绪的实例。When events begin to trigger the app, they are first routed to the always ready instances. 当函数变为活动状态时,其他实例将作为缓冲区进行预热。As the function becomes active, additional instances will be warmed as a buffer. 此缓冲区可防止缩放过程中所需的新实例的冷启动。This buffer prevents cold start for new instances required during scale. 这些缓冲的实例称为预热实例These buffered instances are called pre-warmed instances. 组合使用始终就绪实例和预热缓冲区,你的应用可以有效地消除冷启动。With the combination of the always ready instances and a pre-warmed buffer, your app can effectively eliminate cold start.

备注

每个高级计划在任何时候都至少有一个活动(计费)的实例。Every premium plan has at least one active (billed) instance at all times.

你可以通过以下方式在 Azure 门户中配置始终就绪实例的数目:选择你的 函数应用,转到“平台功能”选项卡,然后选择“横向扩展”选项。You can configure the number of always ready instances in the Azure portal by selected your Function App, going to the Platform Features tab, and selecting the Scale Out options. 在函数应用编辑窗口中,始终就绪实例是该应用特有的。In the function app edit window, always ready instances are specific to that app.

弹性缩放设置

预热实例Pre-warmed instances

预热实例是在缩放和激活事件期间作为缓冲区预热的实例。Pre-warmed instances are instances warmed as a buffer during scale and activation events. 预热实例将持续缓冲,直至达到最大横向扩展限制。Pre-warmed instances continue to buffer until the maximum scale-out limit is reached. 默认的预热实例数为 1,在大多数情况下此值应保留为 1。The default pre-warmed instance count is 1, and for most scenarios this value should remain as 1.

如果应用长时间预热(如自定义容器映像),则可能需要增大此缓冲区。When an app has a long warm-up (like a custom container image), you may need to increase this buffer. 只有充分利用了所有活动实例后,预热实例才会变为活动状态。A pre-warmed instance becomes active only after all active instances have been sufficiently used.

请考虑此示例,了解始终就绪实例和预热实例如何协同工作。Consider this example of how always-ready instances and pre-warmed instances work together. 高级函数应用配置了五个始终就绪实例和一个默认的预热实例。A premium function app has five always ready instances configured, and the default of one pre-warmed instance. 当应用处于空闲状态且未触发任何事件时,应用将通过五个实例进行预配并运行。When the app is idle and no events are triggering, the app is provisioned and running with five instances. 此时,无需为预热实例付费,因为未使用始终就绪实例,并且没有分配预热实例。At this time, you aren't billed for a pre-warmed instance as the always-ready instances aren't used, and no pre-warmed instance is allocated.

一旦第一个触发器进入,五个始终就绪实例将变为活动状态,并分配预热实例。As soon as the first trigger comes in, the five always-ready instances become active, and a pre-warmed instance is allocated. 应用现在运行时有六个预配的实例:五个现在处于活动状态的始终就绪实例,以及第六个预热的处于非活动状态的缓冲区。The app is now running with six provisioned instances: the five now-active always ready instances, and the sixth pre-warmed and inactive buffer. 如果执行速率持续增大,则最终会使用五个活动实例。If the rate of executions continues to increase, the five active instances are eventually used. 当平台决定扩展到五个以上实例时,它将扩展到预热实例。When the platform decides to scale beyond five instances, it scales into the pre-warmed instance. 如果发生这种情况,则现在会有六个活动实例,系统会立即预配第七个实例并填充预热缓冲区。When that happens, there are now six active instances, and a seventh instance is instantly provisioned and fill the pre-warmed buffer. 此缩放和预热序列将继续,直至达到应用的最大实例计数。This sequence of scaling and pre-warming continues until the maximum instance count for the app is reached. 不会预热或激活超出最大值的实例。No instances are pre-warmed or activated beyond the maximum.

可以使用 Azure CLI 为应用修改预热实例数。You can modify the number of pre-warmed instances for an app using the Azure CLI.

az resource update -g <resource_group> -n <function_app_name>/config/web --set properties.preWarmedInstanceCount=<desired_prewarmed_count> --resource-type Microsoft.Web/sites

最大函数应用实例数Maximum function app instances

除了计划最大实例计数之外,还可以配置每个应用的最大值。In addition to the plan maximum instance count, you can configure a per-app maximum. 可以使用应用规模限制配置应用最大值。The app maximum can be configured using the app scale limit.

专用网络连接Private network connectivity

部署到高级计划的函数应用可以利用针对 Web 应用的 VNet 集成Function apps deployed to a Premium plan can take advantage of VNet integration for web apps. 配置后,你的应用可以与 VNet 中的资源通信,或通过服务终结点获得保护。When configured, your app can communicate with resources within your VNet or secured via service endpoints. 应用上也提供 IP 限制,以限制传入流量。IP restrictions are also available on the app to restrict incoming traffic.

在高级计划中向函数应用分配子网时,你需要有一个具有足够 IP 地址的子网,用于每个潜在的实例。When assigning a subnet to your function app in a Premium plan, you need a subnet with enough IP addresses for each potential instance. 我们需要一个至少包含 100 个可用地址的 IP 块。We require an IP block with at least 100 available addresses.

快速弹性缩放Rapid elastic scale

使用与消耗计划相同的快速缩放逻辑,为你的应用自动添加其他计算实例。Additional compute instances are automatically added for your app using the same rapid scaling logic as the Consumption plan. 同一应用服务计划中的应用会基于单个应用的需求彼此独立地进行缩放。Apps in the same App Service Plan scale independently from one another based on the needs of an individual app. 但是,如果可能,同一应用服务计划中的 Functions 应用会共享 VM 资源,以便降低成本。However, Functions apps in the same App Service Plan share VM resources to help reduce costs, when possible. 与某个 VM 关联的应用数取决于每个应用的资源占用情况和 VM 大小。The number of apps associated with a VM depends on the footprint of each app and the size of the VM.

若要详细了解缩放工作原理,请参阅 Azure Functions 中事件驱动的缩放To learn more about how scaling works, see Event-driven scaling in Azure Functions.

更长的运行持续时间Longer run duration

消耗计划中的 Azure Functions 限制为单次执行 10 分钟。Azure Functions in a Consumption plan are limited to 10 minutes for a single execution. 在高级计划中,运行持续时间默认为 30 分钟,以防止执行失控。In the Premium plan, the run duration defaults to 30 minutes to prevent runaway executions. 不过,你可以修改 host.json 配置,使高级计划应用的持续时间无限长。However, you can modify the host.json configuration to make the duration unbounded for Premium plan apps. 如果设置为一个无限的持续时间,则可以保证函数应用至少运行 60 分钟。When set to an unbounded duration, your function app is guaranteed to run for at least 60 minutes.

计划和 SKU 设置Plan and SKU settings

创建计划时,有两个计划大小设置:实例的最小数目(或计划大小)和最大突发限制。When you create the plan, there are two plan size settings: the minimum number of instances (or plan size) and the maximum burst limit.

如果应用需要的实例数超出了始终就绪实例数,则它可以继续横向扩展,直到实例数达到最大突发限制。If your app requires instances beyond the always-ready instances, it can continue to scale out until the number of instances hits the maximum burst limit. 仅当实例正在运行并分配给你时,你才需要为超出计划大小的实例付费(按秒计)。You're billed for instances beyond your plan size only while they are running and allocated to you, on a per-second basis. 平台会尽最大努力将你的应用横向扩展到所定义的最大限制。The platform makes it's best effort at scaling your app out to the defined maximum limit.

在 Azure 门户中,可以通过在计划中或在部署到该计划的函数应用中选择“横向扩展”选项(在“平台功能”下),配置计划大小和最大值。You can configure the plan size and maximums in the Azure portal by selecting the Scale Out options in the plan or a function app deployed to that plan (under Platform Features).

你还可以通过 Azure CLI 提高最大突发限制:You can also increase the maximum burst limit from the Azure CLI:

az functionapp plan update -g <resource_group> -n <premium_plan_name> --max-burst <desired_max_burst>

每个计划的最小值至少为一个实例。The minimum for every plan will be at least one instance. 系统会根据计划中的应用请求的始终就绪实例自动为你配置实际的最小实例数。The actual minimum number of instances will be autoconfigured for you based on the always ready instances requested by apps in the plan. 例如,如果应用 A 请求 5 个始终就绪实例,应用 B 在同一计划中请求 2 个始终就绪实例,则最小计划大小将计算为 5。For example, if app A requests five always ready instances, and app B requests two always ready instances in the same plan, the minimum plan size will be calculated as five. 应用 A 将在所有 5 个实例上运行,应用 B 将仅在 2 个实例上运行。App A will be running on all 5, and app B will only be running on 2.

重要

对于在最小实例计数中分配的每个实例,无论函数是否正在执行,系统都会向你收费。You are charged for each instance allocated in the minimum instance count regardless if functions are executing or not.

在大多数情况下,此自动计算的最小值可以满足需要。In most circumstances, this autocalculated minimum is sufficient. 但是,系统会尽力进行超出最小值的缩放。However, scaling beyond the minimum occurs at a best effort. 如果其他实例不可用,则在特定的时间,横向扩展可能会延迟,虽然这种情况不太可能发生。It's possible, though unlikely, that at a specific time scale-out could be delayed if additional instances are unavailable. 通过将最小值设置为高于自动算出的最小值,可以在横向扩展之前预留实例。By setting a minimum higher than the autocalculated minimum, you reserve instances in advance of scale-out.

可以使用 Azure CLI 为计划增大算出的最小值。Increasing the calculated minimum for a plan can be done using the Azure CLI.

az functionapp plan update -g <resource_group> -n <premium_plan_name> --min-instances <desired_min_instances>

可用的实例 SKUAvailable instance SKUs

创建或缩放计划时,可以在三个实例大小之间进行选择。When creating or scaling your plan, you can choose between three instance sizes. 你将按分配给你的每个实例的内核总数以及每秒的预配内存付费。You will be billed for the total number of cores and memory provisioned, per second that each instance is allocated to you. 你的应用可以根据需要自动横向扩展到多个实例。Your app can automatically scale out to multiple instances as needed.

SKUSKU 核心数Cores 内存Memory 存储Storage
EP1EP1 11 3.5GB3.5GB 250GB250GB
EP2EP2 22 7GB7GB 250GB250GB
EP3EP3 44 14GB14GB 250GB250GB

内存使用情况注意事项Memory usage considerations

在具有更多内存的计算机上运行并不一定意味着函数应用会使用所有可用内存。Running on a machine with more memory doesn't always mean that your function app uses all available memory.

例如,JavaScript 函数应用受 Node.js 中的默认内存限制约束。For example, a JavaScript function app is constrained by the default memory limit in Node.js. 若要增大此固定内存限制,请添加值为 --max-old-space-size=<max memory in MB> 的应用设置 languageWorkers:node:argumentsTo increase this fixed memory limit, add the app setting languageWorkers:node:arguments with a value of --max-old-space-size=<max memory in MB>.

对于内存超过 4GB 的计划,请确保“位数”平台设置在常规设置下设置为 64 BitAnd for plans with more than 4GB memory, ensure the Bitness Platform Setting is set to 64 Bit under General Settings.

区域最大横向扩展Region Max Scale Out

下面是每个区域和 OS 配置中单个计划当前支持的最大横向扩展值。Below are the currently supported maximum scale-out values for a single plan in each region and OS configuration. 若要请求增加,可以创建支持票证。To request an increase, you can open a support ticket.

请在 Azure 网站上查看 Functions 的完整的区域可用性。See the complete regional availability of Functions on the Azure web site.

区域Region WindowsWindows LinuxLinux
澳大利亚中部Australia Central 100100 不可用Not Available
澳大利亚中部 2Australia Central 2 100100 不可用Not Available
澳大利亚东部Australia East 100100 2020
Australia SoutheastAustralia Southeast 100100 2020
Brazil SouthBrazil South 100100 2020
加拿大中部Canada Central 100100 2020
美国中部Central US 100100 2020
中国东部 2China East 2 100100 2020
中国北部 2China North 2 100100 2020
东亚East Asia 100100 2020
美国东部East US 100100 2020
美国东部 2East US 2 100100 2020
法国中部France Central 100100 2020
德国中西部Germany West Central 100100 不可用Not Available
Japan EastJapan East 100100 2020
日本西部Japan West 100100 2020
韩国中部Korea Central 100100 2020
韩国南部Korea South 不可用Not Available 2020
美国中北部North Central US 100100 2020
北欧North Europe 100100 2020
挪威东部Norway East 100100 2020
美国中南部South Central US 100100 2020
印度南部South India 100100 不可用Not Available
Southeast AsiaSoutheast Asia 100100 2020
瑞士北部Switzerland North 100100 不可用Not Available
瑞士西部Switzerland West 100100 不可用Not Available
英国南部UK South 100100 2020
英国西部UK West 100100 2020
USGov ArizonaUSGov Arizona 100100 2020
USGov VirginiaUSGov Virginia 100100 2020
USNat 东部USNat East 100100 不可用Not Available
USNat 西部USNat West 100100 不可用Not Available
西欧West Europe 100100 2020
印度西部West India 100100 2020
美国中西部West Central US 100100 2020
美国西部West US 100100 2020
美国西部 2West US 2 100100 2020

后续步骤Next steps