EventsSourcing-on-Azure-Functions icon indicating copy to clipboard operation
EventsSourcing-on-Azure-Functions copied to clipboard

Use "Throttled Parallelism" for fan-out in commands/queries

Open MerrionComputing opened this issue 4 years ago • 0 comments

Per this blog

public static async Task<string> ScheduleManyInstances(
    IDurableOrchestrationClient client,
    string orchestrationName,
    int count,
    ILogger log)
{
    log.LogWarning($"Scheduling {count} orchestration(s)...");
    DateTime utcNow = DateTime.UtcNow;
    string prefix = utcNow.ToString("yyyyMMdd-hhmmss");

    await Enumerable.Range(0, count).ParallelForEachAsync(200, i =>
    {
        string instanceId = $"{prefix}-{i:X16}";
        return client.StartNewAsync(orchestrationName, instanceId);
    });

    log.LogWarning($"All {count} orchestrations were scheduled successfully!");
    return prefix;
}

Rather than the existing naive parallelism.

MerrionComputing avatar Apr 27 '21 12:04 MerrionComputing