简体   繁体   English

并行耐用的Azure功能

[英]Parallel Durable Azure functions

I have a new durable function to replace a long running webjob and it works well and is faster than the former webjob however I have an issue with parallelism. 我有一个新的持久功能来替换长时间运行的webjob,它运行良好,并且比以前的webjob更快,但是我遇到了并行性问题。

I understand all activities go onto a central work item Q, what this means is that items get processed in order, the issue I have is if there are 10 items in the backlog from user A and user B submits something then user B has to wait till all the data from user A has finished processing. 我了解所有活动都集中在中央工作项目Q上,这意味着项目将按顺序进行处理,我的问题是,如果用户A的待办事项中有10个项目,而用户B提交了某些内容,则用户B必须等待直到来自用户A的所有数据完成处理为止。

With the current webjobs we can autoscale and a new webjob will pickup the data for user B and process it in parallel to the existing processing. 使用当前的Web作业,我们可以自动缩放,新的Web作业将为用户B提取数据并与现有处理并行进行处理。

Am I right in thinking the only way round this is to publish 2 copies of my function, one for each user/client to ensure one user isn't affected by another users backlog of data? 我是否认为这是发布功能的两个副本的唯一方法,每个用户/客户端一个副本,以确保一个用户不受另一个用户积压的数据的影响?

I tried chunking things onto the workitem Q so no single task put more than X items on the Q so that in theory there would be some sharing of the resource but that just slows things down as there is then less on the workitem Q and so the consumption plan autoscaling scales up very slowly due to the smaller volume on the workitem Q. 我尝试将东西分块到工作项Q上,因此没有一个任务在Q上放置超过X个项目,因此理论上会存在一些资源共享,但是这只会减慢速度,因为工作项Q上会更少,所以由于工作项Q上的体积较小,所以消费计划的自动缩放比例会非常缓慢地扩展。

UPDATE 更新

I should have been clearer about why I see the issue, the approx. 我应该更清楚我为什么看到这个问题,大约。 Durable Function process is as follows: 持久功能过程如下:

  • Split file into pages 将文件拆分为页面
  • Fan Out putting an activity on the Q for each page 扇出将活动放在每个页面的Q上
  • Fan In 扇入
  • Fan out putting another activity on the Q for each page (requires data from previous fan out to run) 扇出每页在Q上放置另一个活动(需要从以前的扇出中获取数据才能运行)
  • Fan In 扇入
  • Insert information for pages into the DB in a single transaction 通过一次事务将页面信息插入数据库
  • Mark the file as processed in the DB 将文件标记为已在数据库中处理

So User A loads file 1 that has 1000 pages, then User B loads a file with 100 pages. 因此,用户A加载具有1000页的文件1,然后用户B加载具有100页的文件。

While I appreciate it processes the activity Q in parallel it does still pull things off the Q in order (I assume) so if there are 1000 items on the Q for User A's file when User B's file starts, the initial 100 page activities then get put on the activity Q after the 1000 and hence are "blocked" by them. 虽然我很欣赏它并行处理活动Q,但它仍然可以按顺序拉出Q(我认为),因此,如果用户B的文件启动时用户A的文件上Q上有1000个项目,那么最初的100页活动将得到放在1000之后的活动Q上,因此被他们“阻止”。 Then by the time the 100 initial page activities are done there is a good chance the next fan out for the 1000 page document will have added more items to the activity Q again further blocking the progress of the 100 page document. 然后,当完成100个初始页面活动时,很有可能下一次扇出1000个页面文档将在活动Q中添加更多项,从而进一步阻塞了100页文档的进度。

My issue is User A and B may be 2 different clients who would not expect their work to be blocked by another client's processing, hence my comment about having duplicate instances of the Durable Function and brokering messages between the multiple instances 我的问题是用户A和B可能是2个不同的客户端,他们不希望他们的工作被另一个客户端的处理阻塞,因此我对持久功能的重复实例以及多个实例之间的代理消息的评论

Does that make a bit more sense? 这更有意义吗?

It's true that activities go onto a central work item queue, but they do not get processed in order. 的确,活动进入了中央工作项目队列,但它们没有得到顺序处理。 They will actually get processed in parallel. 它们实际上将并行处理。 The only way things would get processed in order is if there is only one orchestrator function and it intentionally sequences them (see function chaining ). 唯一按顺序处理事物的方法是,只有一个协调器函数并且故意对它们进行排序(请参阅函数链 )。

If work for user A and user B are done using different orchestration instances, or if its a single-instance which uses the fan-out, fan-in pattern , then you will get parallelization and don't have to worry about one user blocking another. 如果用户A和用户B的工作是使用不同的业务流程实例完成的,或者它的单个实例使用扇出,扇入模式 ,那么您将获得并行化,而不必担心一个用户被阻塞另一个。

Also, just FYI, you can tweak the degrees of concurrency using host.json . 此外,仅供参考,您可以使用host.json调整并发host.json More details can be found here: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-perf-and-scale#concurrency-throttles 可以在这里找到更多详细信息: https : //docs.microsoft.com/zh-cn/azure/azure-functions/durable/durable-functions-perf-and-scale#concurrency-throttles

UPDATE 更新

It is true that the queue is shared and large backlogs from one orchestration can cause delays in other orchestrations. 确实,队列是共享的,一个业务流程的大量积压可能会导致其他业务流程的延迟。 In that case there are two possible solutions: 在这种情况下,有两种可能的解决方案:

  1. Add more function app instances to process the backlog faster. 添加更多功能应用实例以更快地处理积压。 This is done for you automatically in the Azure Functions consumption plan, and is done so continuously until the latency for this shared queue becomes suffiently low. 这将在Azure Functions消耗计划中自动为您完成,并持续进行直到此共享队列的等待时间足够短为止。
  2. Create a separate function app with a second task hub for different priority jobs. 使用另一个任务中心创建一个单独的功能应用程序,以处理不同优先级的工作。 Even if you use the same storage account, each task hub will have its own set of queues, so heavy load on one app will not impact the other. 即使您使用相同的存储帐户,每个任务中心也会有自己的队列集,因此一个应用程序的繁重负载不会影响另一个应用程序。

I realize these are not perfect solutions because they don't necessarily ensure fairness. 我意识到这些并不是完美的解决方案,因为它们不一定能确保公平。 If fairness is a strict requirement, then new features may need to be added to support it (BTW, feature requests can be made in the Durable Functions GitHub repo . 如果对公平性有严格的要求,那么可能需要添加新功能来支持它(顺便说一句,可以在Durable Functions GitHub repo中提出功能请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM