运行 来自数据库数据的大量 activity 函数

Running a large amount of activity functions from data from a database

我们有一个数据库,其中包含大约 40 万个需要计算的元素。下面显示了协调器函数的示例。

[FunctionName("Crawl")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext context)
{
   if (!context.IsReplaying)
   {
   }

   WriteLine("In orchistration");
   var outputs = new List<string>();

   var tasks = new Task<string>[3];

   var retryOptions = new RetryOptions(
       firstRetryInterval: TimeSpan.FromSeconds(60),
       maxNumberOfAttempts: 3);

   // Replace "hello" with the name of your Durable Activity Function.
   tasks[0] = context.CallActivityWithRetryAsync<string>("Crawl_Hello",retryOptions, "Tokyo");
   tasks[1] = context.CallActivityWithRetryAsync<string>("Crawl_Hello", retryOptions, "Seattle");
   tasks[2] = context.CallActivityWithRetryAsync<string>("Crawl_Hello",retryOptions, "London");

   await Task.WhenAll(tasks);

   return outputs;
}

每次调用活动时都会调用编排功能。但我不想每次调用 activity 时都从数据库中获取 400k 项。只是在 if 语句中添加所有 activity 代码,或者这里的正确方法是什么?我看不到使用 WaitAll 函数。

Looks like you've figured out the approach for this as you've mentioned in your but elaborating the same here for the benefit of others.

理想情况下,您应该有一个 activity 函数来首先获取您需要的所有数据,对它们进行批处理,然后调用另一个处理该数据的 activity 函数。

由于您有大量元素要计算,最好将计算拆分成单独的 sub-orchestrators,因为扇入操作是在单个实例上执行的。

为了进一步阅读,有一些 documented performance targets 可以在部署持久函数时提供帮助。