I have a web API controller that receives a filter object from the front-end.
The filter basically is just a json array of objects that contains the filtering criteria.
Now based on that filter I have to run a query against an azure API (Azure log analytics api).
This is illustrated in this code snippet :
var tasks = filters.Select(filter=>
{
try
{
return service.GetPerformanceCounters(filter.SComputerId, filter.WorkSpace);
}
catch (Exception ex)
{
return Task.Run(() => new List<Metrics>());
}
})
.ToList();
var metrics = (await Task.WhenAll(tasks))
.SelectMany(metric => metric)
.ToList();
This basically means that if I have 3000 filter object I'll have to run 3000 asynchronous Parallel requests.
But when I was testing this code as I get to 100 filter object the asynchronous parallel tasks fail.
I get the following Exception in the debug panel :
Exception thrown: 'System.Net.Http.HttpRequestException' in Azure.DAL.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in Azure.DAL.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in Azure.DAL.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in Azure.DAL.dll Exception thrown: 'System.Net.Http.HttpRequestException' in Azure.DAL.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll The thread 0x3eac has exited with code 0 (0x0). The thread 0x2294 has exited with code 0 (0x0). The thread 0x66b0 has exited with code 0 (0x0). The thread 0x6958 has exited with code 0 (0x0). The thread 0xb5c has exited with code 0 (0x0). The thread 0x6a98 has exited with code 0 (0x0). The thread 0x16e8 has exited with code 0 (0x0). The thread 0x28f8 has exited with code 0 (0x0).
How to make it possible to run more than 100 async HTTP request without having this problem, I have no control over the number of filters sent from the front but I need to be able to run a number of parallel async operation equivalent to the number of filters.
Edit : Official requested endpoint doc included.
https://dev.loganalytics.io/documentation/Using-the-API/Limits
The doc states that:
Using API key authentication to sample data, throttling rules are applied per client IP address. Each client IP address is able to make up to 200 requests per 30 seconds, with no cap on total calls per day.
Edit : GetPerformanceCounters implementation.
public async Task<List<Entities.Metrics>> GetPerformanceCounters(string sourceComputerId, string workspaceId)
{
Debug.WriteLine("New Task lauched");
// The log analytics query
var query = $@"Perf
| where SourceComputerId == '{sourceComputerId}'
| summarize arg_max(TimeGenerated, *) by SourceComputerId";
var response = await RemoteKustoProvider.RunWorkSpaceQueryAsync
(
workspace: workspaceId,
query: query
);
Debug.WriteLine("Task Finished");
// Send query to the Kusto-Engine.
return JsonConvert.DeserializeObject<List<Entities.Metrics>>
(
response
);
}
Thanks in advance for helping me to solve this issue.