azure服务器_无服务器测试驱动器使用python协调Azure函数

azure服务器

One of the top trends in cloud computing is serverless computing, which allows organizations to access powerful cloud services through code without managing the underlying infrastructure. This allows businesses and governments to focus on functionality and analytics rather than on provisioning virtual machines and administering the software stacks on those machines.

云计算的主要趋势之一是无服务器计算,它使组织可以通过代码访问强大的云服务,而无需管理基础架构。 这使企业和政府可以将精力集中在功能和分析上,而不是在虚拟机上进行配置和管理这些计算机上的软件堆栈。

Image for post

Function as a Service (FaaS) is a serverless offering in which developers can publish code to a cloud provider and have the functions run as needed. Popular cloud functions services include AWS Lambda, Azure Functions, and Google Cloud Functions.

功能即服务(FaaS)是一种无服务器产品,开发人员可以在其中将代码发布到云提供商,并使功能按需运行。 流行的云功能服务包括AWS LambdaAzure FunctionsGoogle Cloud Functions

There are many benefits to serverless functions, including easy deployment, automatic scaling, and reduced cost since a function typically incurs charges only while it’s in use.

无服务器功能有很多好处,包括易于部署,自动扩展和降低成本,因为该功能通常仅在使用时才产生费用。

FaaS functions are usually short-lived and lightweight; they perform a task and then disappear. What if we want to combine Azure Functions into a larger system that achieves a more complex goal? We can now do this easily in Python with Azure Durable Functions. Durable Functions allow us to orchestrate our code into sophisticated patterns that can complete jobs far beyond the ability of individual FaaS functions.

FaaS功能通常是短暂且轻量级的。 他们执行任务,然后消失。 如果我们想将Azure Functions组合到一个实现更复杂目标的更大系统中怎么办? 现在,我们可以在具有Azure耐用功能的Python中轻松完成此操作。 耐用的功能使我们能够将代码编排为复杂的模式,这些模式可以完成远远超出单个FaaS功能的能力的工作。

This GitHub repository uses the new Python extension for Azure Durable Functions to deploy an advanced regime-switching regression model using 100% Python. It coordinates a collection of smaller functions into a greater whole that estimates a regime-switching model and produces results in the form of charts, JSON files, and email notifications.

GitHub存储库使用Azure耐用功能的新Python扩展来使用100%Python部署高级的方案切换回归模型。 它将较小的功能集合协调为一个更大的整体,以估计一种政权转换模型,并以图表,JSON文件和电子邮件通知的形式产生结果。

Python中的持久函数 (Durable Functions in Python)

Azure Durable Functions for the C# programming language became widely available on May 7, 2018, with support for JavaScript and F# coming thereafter.

适用于C#编程语言的Azure耐用功能2018年5月7日广泛可用,此后将支持JavaScript和F#。

Microsoft released function orchestration in Python on June 24, 2020. This is a public preview, meaning that users can work with it while it is in development. A preview version doesn’t have the standard Azure warranties and service-level agreements.

微软于2020年6月24日发布了Python中的函数编排。这是一个公开预览,这意味着用户可以在开发过程中使用它。 预览版没有标准的Azure保证和服务级别协议。

The Azure team continues to add more options for using Python. For instance, nested orchestrations became available on July 28, although the durable entities described below are not yet supported.

Azure团队继续为使用Python添加更多选项。 例如,嵌套的业务流程已于7月28日可用,尽管尚不支持以下持久性实体。

精心策划的模式 (Orchestrated Patterns)

Azure Durable Functions are triggered by a client function, which starts the broader choreography by calling an orchestrator function. The orchestrator organizes the arrangement of the activity functions, which do most of the work. Another type of Durable Function is the entity function, which holds a state and can change that state as additional information arrives.

Azure耐用功能由客户端功能触发,客户端功能通过调用协调器功能来启动更广泛的编排。 协调器组织活动功能的安排,这些活动将完成大部分工作。 持久函数的另一种类型是实体函数,它拥有一个状态并可以在其他信息到达时更改该状态。

There are several common orchestration patterns:

有几种常见的编排模式

Image for post

Chaining: This runs Azure Functions in a sequence where each function begins after the previous one finishes. This differs from traditional sequential programming because each activity function can be its own Azure Function instance, and the rest of the architecture scales to zero (goes to sleep) while an individual component works on its task.

链接:这按顺序运行Azure Functions,其中每个函数在上一个函数完成后开始。 这不同于传统的顺序编程,因为每个活动功能都可以是其自己的Azure Function实例,并且体系结构的其余部分可以缩放为零(进入睡眠状态),而单个组件则可以执行其任务。

Fan out/fan in: This pattern runs a series of Azure Functions in parallel. It speeds up response time by running independent tasks concurrently. For example, a large data transformation job can be split up into many pieces that get processed at the same time.

扇出/扇入:此模式并行运行一系列Azure函数。 通过同时运行独立的任务,它可以加快响应时间。 例如,大型数据转换作业可以分为多个片段,这些片段可以同时处理。

Async HTTP: This exposes a status endpoint that indicates when a job finishes. This eliminates the need to hold an HTTP connection open for an extended time, which is an unreliable way to communicate over the internet.

异步HTTP :这公开了一个状态端点,指示作业何时完成。 这样就无需长时间保持HTTP连接打开,而这是通过Internet进行通信的不可靠方法。

Monitor: This is a long-running Durable Function that runs at intervals to check on the status of another process and take corrective action if needed.

监视器:这是一个长期运行的耐用功能,它会定期运行以检查另一个进程的状态,并在需要时采取纠正措施。

Watcher: Similar to the monitor pattern, this is an Azure Function that runs at intervals and completes an assignment, such as reading data from a website.

守望者:在监视器模式相似,这是一个Azure的功能,在间隔运行,并完成一个任务,比如从网站读取数据。

External interaction: A Durable Function architecture can scale to zero while it waits for information from an external source, such as a human’s manual input. After receiving the information, the Durable Function wakes up to carry on with its work.

外部交互:耐久功能体系结构在等待来自外部源的信息(例如人工输入)时可以扩展为零。 收到信息后,耐用功能会唤醒以继续其工作。

Aggregator: This is a Durable Function that receives a stream of data and organizes the information. This pattern makes use of entity functions to create stateful durable entities.

聚合器:这是一种持久功能,用于接收数据流并组织信息。 此模式利用实体功能创建有状态的持久性实体

Durable entities are not yet available in Python, although Microsoft is accepting feedback about how Azure users would want to use this pattern.

尽管Microsoft接受有关Azure用户希望如何使用此模式的反馈,但Python中尚不提供持久实体。

Sub-orchestrations: Orchestrated designs can be organized into nested sub-patterns. This increases the range of possibilities for what can be accomplished with Azure Functions.

子编排:可以将编排的设计组织为嵌套的子样式。 这增加了Azure功能可以实现的可能性范围。

计费方案 (Billing Plans)

This project uses Azure Durable Functions on the Consumption plan, in which ephemeral functions appear and disappear, and they only accumulate costs while they are running.

此项目在“消费”计划上使用Azure耐用功能,其中临时功能会出现和消失,并且它们仅在运行时累积成本。

There are different function plans available on Azure. For instance, if a service has a predictable demand, the Premium or App Service plans can ensure that there are always virtual machines ready to respond quickly. These plans can also accommodate more conventional long-running programs.

Azure上提供了不同的功能计划。 例如,如果服务的需求是可预测的,那么高级或应用服务计划可以确保始终有虚拟机准备快速响应。 这些计划还可以容纳更多常规的长期运行程序。

The number of function calls is one factor in pricing for the Consumption plan, and a Durable Functions architecture likely increases the number of function requests. For high-volume applications, this might make an alternative billing plan look more appealing.

函数调用的数量是使用计划定价的一个因素,而“耐用函数”体系结构可能会增加函数请求的数量。 对于大批量的应用程序,这可能会使替代的计费计划显得更具吸引力。

There are other costs besides function execution. For instance, Durable Functions communicate with each other through messages, and these messages may be quite large for some applications. There are several ways to purge instance history to avoid unnecessary storage charges.

除了执行功能外,还有其他成本。 例如,耐用功能通过消息相互通信,对于某些应用程序,这些消息可能会很大。 有几种清除实例历史记录的方法,以避免不必要的存储费用。

体制转换模型 (Regime-switching Models)

In a traditional linear regression, the coefficients on the independent (x) variables are constant throughout the sample. But many times, a sequence has distinct regimes in which the influence of the independent variables on the dependent (y) variable changes.

在传统的线性回归中,自变量( x )的系数在整个样本中都是恒定的。 但是很多时候,一个序列具有不同的机制,其中自变量对因变量( y )的影响发生变化。

If these regimes are predictable, such as day vs. night, or if these changes develop consistently through time, it’s possible to capture these regimes in a standard regression by having the coefficients change dynamically based on other factors (such as time).

如果这些体制是可预测的(例如白天与黑夜),或者这些变化随着时间不断发展,则可以通过使系数根据其他因素(例如时间)动态变化来以标准回归方式捕获这些体制。

Image for post

Regime-switching models are useful for unpredictable regime changes, such as what we see in weather, stock market volatility, and sentiment analysis. This topic is important enough that it’s inspired the development of regime-switching neural networks.

政权转换模型对于不可预测的政权变化非常有用,例如我们在天气,股市波动和情绪分析中所看到的。 这个主题非常重要,它激发了状态切换神经网络的发展。

This GitHub repository is an Azure Durable Functions project that calculates the regime-switching model of James D. Hamilton. [1, 2] There has been a great deal of innovation in these techniques since Hamilton’s initial publications, and a Web search for endogenous regime-switching models gives examples of more recent work. The original Hamilton model does a decent job of finding distinct regimes, and it provides for a good demonstration of Azure Durable Functions.

该GitHub存储库是一个Azure耐用功能项目,该项目计算James D.Hamilton的政权转换模型。 [1,2]自从汉密尔顿(Hamilton)最初发表以来,这些技术已经进行了很多创新,并且对内源性政权转换模型的网络搜索提供了更多最新工作的实例。 最初的汉密尔顿模型在找到不同的机制方面做得不错,并且很好地演示了Azure持久功能。

Azure体系结构 (Azure Architecture)

The client function for this application receives an HTTP request that contains settings for the model and the data to be analyzed. It’s possible to send such a request directly to an Azure Function App, but this program uses Azure API Management. Azure’s API service offers many benefits, such as throttling, input/output transformations, authentication and authorization, caching, and a developer portal where users can register subscriptions.

此应用程序的客户端功能接收HTTP请求,该请求包含模型设置和要分析的数据。 可以直接将此类请求发送到Azure Function应用,但是此程序使用Azure API管理。 Azure的API服务提供了许多好处,例如节流,输入/输出转换,身份验证和授权,缓存以及用户可以在其中注册订阅的开发人员门户。

Image for post

The API gateway for this program passes the request information to the client function, which validates the data and returns an immediate response. If the data fails validation, this reply will contain a description of the error. Otherwise, this message will contain a list of URLs where the outputs will be located.

该程序的API网关将请求信息传递给客户端功能,客户端功能将验证数据并返回立即响应。 如果数据验证失败,则此回复将包含对错误的描述。 否则,此消息将包含输出将位于的URL列表。

After passing validation, the client function calls the orchestrator, which initiates multiple instances of the activity function that estimates the regime-switching model. This is the fan-out/fan-in pattern, and it’s helpful because this model uses a specialized iterative procedure created by James D. Hamilton. The algorithm is fast, but this implementation sometimes takes a suboptimal path and returns an inadequate result. Running this routine several times in parallel lets us select a high-quality optimization without sacrificing response time.

通过验证后,客户端函数将调用协调器,该协调器将启动活动函数的多个实例,以估计状态切换模型。 这是扇出/扇入模式,这很有用,因为此模型使用了James D. Hamilton创建的专门的迭代过程。 该算法速度很快,但是此实现有时会采用次优路径,并且返回的结果不足。 并行运行此例程几次使我们可以选择高质量的优化,而不会牺牲响应时间。

After calculating the regime-switching model, the orchestrator creates a second fan-out/fan-in pattern in which certain time-consuming tasks, such as calculating t-statistics, are performed in parallel. Running these jobs concurrently reduces the time it takes to deliver a result.

在计算了状态切换模型之后,协调器创建了第二个扇出/扇入模式,其中某些耗时的任务(例如计算t统计量)并行执行。 同时运行这些作业可以减少交付结果所需的时间。

The orchestrator then calls an activity function that saves the final output to Azure Blob storage. After everything is completed, the orchestrator calls an optional activity function that emails the customer notifying them that the output files are ready. (Alternatively, the customer can poll the URLs from the initial HTTP response until the files appear.)

然后,协调器调用一个活动函数,该函数将最终输出保存到Azure Blob存储中。 完成所有操作后,协调器将调用一个可选的活动功能,该功能通过电子邮件向客户发送电子邮件,通知他们输出文件已准备就绪。 (或者,客户可以轮询初始HTTP响应中的URL,直到出现文件为止。)

要求 (Requirements)

To install and run this application in Azure, one needs an Azure account, an Azure storage account to host the function app and the results, and an API Management subscription.

要在Azure中安装和运行此应用程序,需要一个Azure帐户,一个用于托管功能应用程序和结果的Azure存储帐户以及一个API管理订阅。

Within the storage account, this program needs a container named “results” to store the output. This container should have the access level “anonymous read access for blobs only.” This will allow customers to read their output files, which are named with a universally unique identifier.

在存储帐户中,此程序需要一个名为“结果”的容器来存储输出。 该容器应具有访问级别“仅对blob进行匿名读取访问”。 这将使客户能够读取其输出文件,该文件以通用唯一标识符命名。

A SendGrid account is also required to send the optional notification emails.

还需要一个SendGrid帐户来发送可选的通知电子邮件。

The storage endpoint, storage access key, and SendGrid key are located in the “local.settings.json” file to avoid placing sensitive information into programming code. The values in this file can be uploaded to Azure when deploying a Function App through Visual Studio Code.

存储端点,存储访问密钥和SendGrid密钥位于“ local.settings.json”文件中,以避免将敏感信息放入编程代码中。 通过Visual Studio Code部署功能应用程序时,可以将该文件中的值上载到Azure。

For enhanced security, access keys can be stored in the Azure Key Vault rather than through the settings file.

为了增强安全性,可以将访问密钥存储在Azure Key Vault中,而不是通过设置文件存储。

测试与结果 (Testing & Results)

This repository has a folder named “test-demo” that contains a Python program for testing the regime-switching application. The demo program creates a data set with three regimes and runs a separate linear regression for each regime, printing the results to the console. The script then calls the regime-switching application through the API gateway. (This testing program therefore requires an API subscription key that grants access to a deployed version of the regime-switching application.)

该存储库有一个名为“ test-demo ”的文件夹,其中包含用于测试状态切换应用程序的Python程序。 该演示程序创建具有三个方案的数据集,并对每个方案运行单独的线性回归,然后将结果打印到控制台。 然后,该脚本通过API网关调用状态切换应用程序。 (因此,此测试程序需要一个API订阅密钥,该密钥可授予对权限切换应用程序已部署版本的访问权限。)

Image for post

If all goes well, the results from the regressions should be close to the regime-switching outputs. This is what we see from the testing routine, and this indicates we’ve completed a working example of the new Azure Durable Functions library for Python!

如果一切顺利,回归的结果应该接近政权转换的输出。 这是我们从测试例程中看到的内容,这表明我们已经完成了适用于Python的新Azure耐用函数库的工作示例!

This application gives an example of the type of intelligence that can be a good candidate for Azure Durable Functions. This technique is too involved for most people to program themselves, and it’s something people might seek from a service. On the other hand, this model isn’t nearly at the scale of training a deep learning neural network, which often requires GPU-capable virtual machines.

此应用程序给出了可以作为Azure持久功能的最佳候选者的智能类型的示例。 对于大多数人来说,这项技术太复杂了,无法自行编程,这是人们可能会从服务中寻求的东西。 另一方面,该模型几乎不适合训练深度学习神经网络,后者通常需要具有GPU功能的虚拟机。

The new Python extension for Azure Durable Functions is available and capable, and it decreases the barrier to entry for deploying intelligent applications to the cloud. With Durable Functions, people can orchestrate function patterns that use the full array of Azure serverless options, including compute, storage, databases, artificial intelligence, events, and messaging.

适用于Azure耐用功能的新Python扩展已可用并且具有功能,它减少了将智能应用程序部署到云的入门障碍。 借助持久功能,人们可以编排使用Azure无服务器选项的全部功能的功能模式,包括计算,存储,数据库,人工智能,事件和消息传递。

GitHub repository: https://github.com/hergott/regime-switching

GitHub存储库: https : //github.com/hergott/regime-switching

Matt Hergott is a certified Azure Solutions Architect Expert and AWS Solutions Architect — Professional.

Matt Hergott是一位经过认证的Azure解决方案架构师专家和AWS解决方案架构师-专业人士。

汉密尔顿模型 (Hamilton Model)

[1] Hamilton, James D. (1989), “A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle,” Econometrica 57, 357–384.

[1] Hamilton,James D.(1989),“非平稳时间序列和商业周期的经济分析的新方法,” Econometrica 57,357-384。

[2] Hamilton, James D. (1994), Time Series Analysis, Princeton, NJ: Princeton University Press.

[2] Hamilton,James D.(1994),时间序列分析,新泽西州普林斯顿:普林斯顿大学出版社。

翻译自: https://medium.com/swlh/serverless-test-drive-orchestrating-azure-functions-with-python-ea8463eefb81

azure服务器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值