Azure Durable Function 生成错误 'Host thresholds exceeded: Connections' 和 CloudTable.ExecuteBatchAsync

Azure Durable Function generates error 'Host thresholds exceeded: Connections' with CloudTable.ExecuteBatchAsync

我正在使用 Azure Durable Function。

我发现 it hits the connections' limit:

我已经能够识别负责达到限制的调用:

public class RecordStorage : IRecordStorage
{
    private readonly CloudTableClient m_cloudTableClient;

    public RecordStorage()
    {
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(/* Connection string */);
        m_cloudTableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
        m_cloudTableClient.DefaultRequestOptions.RetryPolicy = Constants.Storage.RetryPolicy;
    }

    public async Task UpsertAsync(string listId, ICollection<RecordBatch> recordBatches)
    {
        CloudTable cloudTable = m_cloudTableClient.GetTableReference(listId);

        var tasks = new List<Task>();

        foreach(var recordBatch in recordBatches)
        {
             var tableBatchOperation = new TableBatchOperation();

             foreach(var batch in recordBatch.Records)
                  tableBatchOperation.Add(TableOperation.InsertOrReplace(new SomeTableEntity(***)));

             /* THIS IS THE CALL THAT APPEAR TO BE CAUSING THE SPIKE OF CONNECTION */
             tasks.Add(cloudTable.ExecuteBatchAsync(tableBatchOperation));
        }

        await Task.WhenAll(tasks);
    }
}

此方法在 activity 中间接调用。

我不明白为什么它会达到极限,因为我确保重用 CloudTableClient 实例。我还确保 RecordStorage 的实例作为单例注入到另一个 类 中:

public class Startup : FunctionsStartup
{
   public override void Configure(IFunctionsHostBuilder builder)
   {
        builder.Services.AddSingleton<IRecordStorage, RecordStorage>();
   }
}

问题

如果我继续重复使用同一个 CloudTableClient 实例,为什么会超出连接限制?

这很尴尬。我想我刚刚在指标图表中选择了错误的聚合方法。我选择了 Max 聚合,但我应该选择 Count。这是同期的图表:

以及全天的图表: