I'm using the following logic that seems to run in parallel when running locally, but when deployed on azure functions, it's running sequencially:
var allRecordTasks = new List<Task<DataRecord>>();
for (int i = 0; i < 100; i++)
{
allRecordTasks.Add(Task.Run(() => MyTask(cancellationToken)));
}
await Task.WhenAll(allRecordTasks);
I'm running under S1 plan and I was under the assumption that a single core could run multiple threads.
Is there some setting to make this work, is it possible when running a plan with multiple cores or is it simply not possible without using durable functions?
private async Task<DataRecord> MyTask(CancellationToken cancellationToken)
{
var timeSeriesType = await GetTimeSeriesTypeAsync();
var dataRecord = new DataRecord(timeSeriesType);
return dataRecord;
}
Update: Simply using
allRecordTasks.Add(MyTask(cancellationToken));
ran in parallel. Other issues in my code caused the CPU core to be busy, which didn't cost much locally (quad-core), but prevented performance on a single core. Thanks Peter Bons and Stephen Cleary for clearing things up, pointing me in the right direction.