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. 高级计划提供 VNet 连接、无冷启动以及高级硬件等功能。The Premium plan provides features like VNet connectivity, no cold start, and premium hardware. 可以将多个函数应用部署到同一高级计划,该计划允许配置计算实例大小、基本计划大小和最大计划大小。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. 有关高级计划以及其他计划和承载类型的比较,请参阅函数缩放和承载选项For a comparison of the Premium plan and other plan and hosting types, see function scale and hosting options.

创建高级计划Create a Premium plan

  1. 在 Azure 门户菜单或“主页”页中,选择“创建资源” 。From the Azure portal menu or the Home page, select Create a resource.

  2. “新建” 页面,选择 “计算” > “函数应用”In the New page, select Compute > Function App.

  3. 在“基本信息”页面上,按照下列所述使用函数应用设置:On the Basics page, use the function app settings as specified in the following table:

    设置Setting 建议的值Suggested value 说明Description
    订阅Subscription 订阅Your subscription 要在其下创建此新函数应用的订阅。The subscription under which this new function app is created.
    资源组Resource Group myResourceGroupmyResourceGroup 要在其中创建 Function App 的新资源组的名称。Name for the new resource group in which to create your function app.
    函数应用名称Function App name 全局唯一名称Globally unique name 用于标识新 Function App 的名称。Name that identifies your new function app. 有效字符为 a-z(不区分大小写)、0-9-Valid characters are a-z (case insensitive), 0-9, and -.
    发布Publish 代码Code 用于发布代码文件或 Docker 容器的选项。Option to publish code files or a Docker container.
    运行时堆栈Runtime stack 首选语言Preferred language 选择支持你喜欢的函数编程语言的运行时。Choose a runtime that supports your favorite function programming language. 对于 C# 和 F# 函数,选择 .NETChoose .NET for C# and F# functions.
    区域Region 首选区域Preferred region 选择离你近或离函数访问的其他服务近的区域Choose a region near you or near other services your functions access.

    “基本信息”页

  4. 在完成时选择“下一步:托管”。Select Next: Hosting. 在“托管”页面上,输入以下设置:On the Hosting page, enter the following settings:

    设置Setting 建议的值Suggested value 说明Description
    存储帐户Storage account 全局唯一名称Globally unique name 创建函数应用使用的存储帐户。Create a storage account used by your function app. 存储帐户名称必须为 3 到 24 个字符,并且只能包含数字和小写字母。Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only. 也可使用现有帐户,但该帐户必须符合存储帐户要求You can also use an existing account, which must meet the storage account requirements.
    操作系统Operating system 首选操作系统Preferred operating system 系统会根据你的运行时堆栈选择为你预先选择一个操作系统,但你可以根据需要更改该设置。An operating system is pre-selected for you based on your runtime stack selection, but you can change the setting if necessary. Python 仅在 Linux 上受支持。Python is only supported on Linux.
    计划Plan PremiumPremium 定义如何将资源分配给 Function App 的托管计划。Hosting plan that defines how resources are allocated to your function app. 选择“高级”。Select Premium. 默认创建一个新的应用服务计划。By default, a new App Service plan is created. 默认的“SKU 和大小”为 EP1,其中 EP 表示“弹性高级”(elastic premium) 。The default Sku and size is EP1, where EP stands for elastic premium. 要了解详细信息,请参阅高级 SKU 的列表To learn more, see the list of Premium SKUs.
    在高级计划上运行 JavaScript 函数时,应选择 vCPU 数更少的实例。When running JavaScript functions on a Premium plan, you should choose an instance that has fewer vCPUs. 有关详细信息,请参阅选择单核心高级计划For more information, see Choose single-core Premium plans.

    “托管”页

  5. 在完成时选择“下一步:监视”。Select Next: Monitoring. 在“监视”页面上,输入以下设置:On the Monitoring page, enter the following settings:

    设置Setting 建议的值Suggested value 说明Description
    Application InsightsApplication Insights 默认Default 在最近的受支持的区域中,创建一个具有相同应用名称的 Application Insights 资源。Creates an Application Insights resource of the same App name in the nearest supported region. 展开此设置即可更改“新建资源名称”,或者在 Azure 地理位置选择其他位置来存储你的数据 。By expanding this setting, you can change the New resource name or choose a different Location in an Azure geography to store your data.

    “监视”页

  6. 选择“查看 + 创建”,以便查看应用配置选择。Select Review + create to review the app configuration selections.

  7. 在“查看 + 创建”页上查看设置,然后选择“创建”来预配并部署函数应用 。On the Review + create page, review your settings, and then select Create to provision and deploy the function app.

  8. 选择门户右上角的“通知”图标,留意是否显示了“部署成功”消息。 Select the Notifications icon in the upper-right corner of the portal and watch for the Deployment succeeded message.

  9. 选择“转到资源”,查看新的函数应用。Select Go to resource to view your new function app. 还可选择“固定到仪表板”。You can also select Pin to dashboard. 固定可以更轻松地从仪表板返回此函数应用资源。Pinning makes it easier to return to this function app resource from your dashboard.

    部署通知

你还可以在 Azure CLI 中使用 az functionapp plan create 创建高级计划。You can also create a Premium plan using az functionapp plan create in the Azure CLI. 下面的示例创建一个“弹性高级版 1”层计划:The following example creates an Elastic Premium 1 tier plan:

az functionapp plan create --resource-group <RESOURCE_GROUP> --name <PLAN_NAME> \
--location <REGION> --sku EP1

在此示例中,请将 <RESOURCE_GROUP> 替换为资源组,并将 <PLAN_NAME> 替换为你的计划的名称,该名称在资源组中是独一无二的。In this example, replace <RESOURCE_GROUP> with your resource group and <PLAN_NAME> with a name for your plan that is unique in the resource group. 指定一个受支持的 <REGION>Specify a supported <REGION>.

创建计划后,可以使用 az functionapp create 创建你的函数应用。With the plan created, you can use az functionapp create to create your function app. 在门户中,计划和应用是同时创建的。In the portal, both the plan and the app are created at the same time. 有关完整 Azure CLI 脚本的示例,请参阅在高级计划中创建函数应用For an example of a complete Azure CLI script, see Create a function app in a Premium plan.

功能Features

以下功能可供部署到高级计划的函数应用使用。The following features are available to function apps deployed to a Premium plan.

始终就绪实例Always ready instances

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

在高级计划中,你可以让应用在指定数量的实例上始终处于就绪状态。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 routed to the always ready instances first. 当函数变为活动状态时,其他实例将作为缓冲区进行预热。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 will have 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.

弹性缩放设置

你还可以使用 Azure CLI 为应用配置始终就绪实例。You can also configure always ready instances for an app with the Azure CLI.

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

预热实例Pre-warmed instances

预热实例是在缩放和激活事件期间作为缓冲区预热的实例数。Pre-warmed instances are the number of 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 should remain as 1. 如果应用长时间预热(如自定义容器映像),则可能需要增大此缓冲区。If an app has a long warm up (like a custom container image), you may wish to increase this buffer. 只有在充分利用了所有活动实例后,预热实例才会变为活动状态。A pre-warmed instance will become active only after all active instances have been sufficiently utilized.

请考虑此示例,了解始终就绪实例和预热实例如何协同工作。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 will be provisioned and running on five instances. 此时,无需为预热实例付费,因为未使用始终就绪实例,甚至没有分配预热实例。At this time, you will not be billed for a pre-warmed instance as the always ready instances aren't used, and no pre-warmed instance is even 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 will eventually be utilized. 当平台决定扩展到五个以上实例时,它将扩展到预热实例。When the platform decides to scale beyond five instances, it will scale into the pre-warmed instance. 如果发生这种情况,则现在会有六个活动实例,系统会立即预配第七个实例并填充预热缓冲区。When that happens, there will now be six active instances, and a seventh instance will instantly be provisioned and fill the pre-warmed buffer. 此缩放和预热序列将继续,直至达到应用的最大实例计数。This sequence of scaling and pre-warming will continue until the maximum instance count for the app is reached. 不会预热或激活超出最大值的实例。No instances will be 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 instances for an app

除了计划最大实例计数之外,还可以配置每个应用的最大值。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

部署到高级计划的 Azure Functions 会利用针对 Web 应用的新 VNet 集成Azure Functions deployed to a Premium plan takes advantage of new 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.

若要详细了解缩放的工作原理,请参阅函数缩放和承载To learn more about how scaling works, see Function scale and hosting.

更长的运行持续时间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 配置,使高级计划应用的持续时间无限长(保证 60 分钟)。However, you can modify the host.json configuration to make the duration unbounded for Premium plan apps (guaranteed 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 are billed for instances beyond your plan size only while they are running and allocated to you, on a per-second basis. 我们将尽最大努力将你的应用横向扩展到其定义的最大限制。We will make a best effort at scaling your app out to its 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 should be sufficient. 但是,系统会尽力进行超出最小值的缩放。However, scaling beyond the minimum occurs at a best effort. 如果其他实例不可用,则在特定的时间,横向扩展可能会延迟,虽然这种情况不太可能发生。It is 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 utilization considerations

在具有更多内存的计算机上运行并不一定意味着函数应用将使用所有可用内存。Running on a machine with more memory does not always mean that your function app will use 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>.

区域最大横向扩展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, please open a support ticket.

请在此处查看 Functions 的完整的区域可用性:Azure.comSee the complete regional availability of Functions here: Azure.com

区域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