Can we run out of available threads if we execute bunch of asynchronous I/O operations?

74 Views Asked by At

I have a method like this:

private Task GetLiveData(List<string> keys, ConcurrentBag<LiveData> resultsBag, CancellationToken cancellationToken)
{
     var tasks = new List<Task>();

     foreach (var key in keys)
     {
          cancellationToken.ThrowIfCancellationRequested();
          tasks.Add(ExecuteOne(assetId, semafore, resultsBag, cancellationToken));
     }

     return Task.WhenAll(tasks);
}

ExecuteOne method is execute asynchronous I/O operation and also convert data from redis to the model, but main part is async I/O operation (read from Redis)

If for example count of keys will be 10_000, then we will call Redis 10_000 times and add this to the list of tasks,

and my question is: Can we run out of available threads in threapool during this process (10_000 keys it's just example there could be more) so we will have threadpool starvation? If so, so what will be then, will it go to the queue and wait until thread will be available or will add a new thread to threadpool?

I'm not so acknowledged in this topic, so maybe my opinion is wrong

Thank you in advance

0

There are 0 best solutions below