MerrionComputing / EventsSourcing-on-Azure-Functions

A library to demonstrate doing Event Sourcing as a data persistence mechanism for Azure Functions
MIT License
103 stars 20 forks source link

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

Open MerrionComputing opened 3 years ago

MerrionComputing commented 3 years ago

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.