Search code examples
c#azure-blob-storageservicepointmanager

Should I set ServicePointManager.DefaultConnectionLimit in a console application


I am calling this line of code 50000 times in a console application running as webjob in azure:

await cloudBlockBlob.UploadFromFileAsync(sourceFile); // 50 kb files only

Should I care at all about setting ServicePointManager.DefaultConnectionLimit to any other value than the default one?

Can I see somehow or calculate how many connections are used in average for the whole upload to judge wether the default value is fine or I need to increase the value?


Solution

  • Assuming your not using .NET Core yes. On .Net Full framework ServicePointManager.DefaultConnectionLimit is 2 by default. If you want better parallelism set it higher your mileage will vary but start with 20 - 50 and benchmark you should be able to find the optimal value for your situation.

    Also bare in mind Azure limits, and handle throttling appropriately.

    https://learn.microsoft.com/en-us/azure/azure-subscription-service-limits#storage-limits