异步功能有好处吗? [英] Are there benefits to an async function?

查看:87
本文介绍了异步功能有好处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure函数允许我编写在特定条件下执行的C#/F#(及更多)函数.这些功能可以是异步的(通过返回一个Task).

Azure functions allows me to write C#/F# (and more) functions which are executed given certain conditions. These functions can be async (by returning a Task).

关于天蓝色函数的有趣的事情是它们会根据负载自动扩大规模.关于经典"服务器上的异步/等待模式的一件很酷的事情是,您可以更好地利用这些内核,以便处理更多的请求.

The cool thing about azure functions is that they automatically scale up depending on load. One of the cool things about the async/await pattern on a "classic" server, is that you can better utilize the cores so you can handle more requests.

由于天青函数会自动缩放,因此编写异步函数对我有什么好处?

Since azure functions automagically scales, are there any benefits for me to write async functions?

推荐答案

出于与其他任何应用程序相同的原因,您将在Azure Functions中使用async.对于那些可能长时间运行的外部I/O阻塞的操作,这将是对资源的更有效利用. Azure Functions完全支持运行时核心中的异步,因此,如果使用得当,它将在单个Function App上提供更多的并行性和更好的吞吐量,因为不会阻塞线程等待I/O,并且可用于处理更多的请求/触发

You'd use async in Azure Functions for the same reasons you would in any other application. For operations that block on potentially long running external I/O, it'll be a much more efficient use of resources. Azure Functions fully supports async in the runtime core, so when used correctly, it will allow for more parallelism and better throughput on a single Function App since threads aren't blocked waiting for I/O and can be used to process more requests/triggers.

如果您的Function App运行在经典SKU 上,则您需要为Always On实例付费,因此很显然,您希望尽可能有效地利用资源.

If your Function App is running on a Classic SKU, then you're paying for an Always On instance, so it's clear you want to use resources as efficiently as possible.

动态SKU 中运行时,我认为您的问题是,如果我们仅根据需要扩展您的功能,那么谁在乎他们是否在有效地使用资源?我仍然要说,最好是对函数进行编码,以使它们尽可能高效地运行.这样,我们仅在真正需要时向外扩展,并在新实例启动时最大程度地减少新实例的冷启动时间.

When running in the Dynamic SKU, I think your question was that if we'll just scale out your functions as needed, then who cares if they're using resources efficiently? I'd still say that it is best for you to code your functions so they run as efficiently as possible. That way we're only scaling you out when truly needed, and minimizing any cold start times for new instances as we spin them up.

这篇关于异步功能有好处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆