-1

I've been doing some research on I/O threads buts I'm a bit confused on how the system determines the limits.

According to the MSDN:

If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using GetMaxThreads), SetMinThreads returns false and does not change either of the minimum values.

When I Call:

//Max IO Threads is 1000
//max Works is set to 32767
ThreadPool.GetMaxThreads(out var maxWorker, out var maxIO);

How does the system determine that I can only have 1000 I/O threads, and is there anyway to increase that limit?

As the documentation states setting the number larger than the max will have no effect

johnny 5
  • 19,893
  • 50
  • 121
  • 195
  • 3
    1000 I/O threads seems like a lot. Why do you want more? – Kredns Jan 23 '18 at 22:23
  • Please see https://stackoverflow.com/questions/145312/maximum-number-of-threads-in-a-net-app – Teoman shipahi Jan 23 '18 at 22:23
  • @Kredns I agree it is a lot, We're doing some load testing. We have a lot of could that should be Implemented Async, but it is not. – johnny 5 Jan 23 '18 at 22:25
  • @Teomanshipahi thanks for the link, but that looks like it's only applicable to the worker threads, my issue is the portCompletionThreads – johnny 5 Jan 23 '18 at 22:26
  • 1
    You can increase your completion port threads with the second argument in `ThreadPool.SetMaxThreads`. Such as `ThreadPool.SetMaxThreads(numWorkerThreads, numCompletionPortThreads)`. I'm not sure how the system determined 1000, though. – Will Ray Jan 23 '18 at 22:28
  • MSDN is only telling you that minThread can't be bigger than maxThread (which seems logical). But you can increase maxThread by calling `SetMaxThreads` – Kevin Gosse Jan 23 '18 at 22:35
  • @WillRay This will not be able to be set above the max amount of 1000 – johnny 5 Jan 23 '18 at 22:36
  • @johnny5 Are you sure? In a quick test on my local machine I was able to raise it to 2000, at least. – Will Ray Jan 23 '18 at 22:42
  • @WillRay apparently it’s based on the max threads set, you need to potentially set it first if your picking a larger number than the unknown default – johnny 5 Jan 23 '18 at 23:55

1 Answers1

3

MSDN is just telling you that SetMinThread can't be used with a value bigger than the current maximum number of thread. But that number can be changed by calling SetMaxThread:

ThreadPool.GetMaxThreads(out var worker, out var io);
Console.WriteLine(io); // 1000

ThreadPool.SetMaxThreads(worker, 32000);
ThreadPool.GetMaxThreads(out worker, out io);
Console.WriteLine(io); // 32000

The only limit enforced is 32767. You can't set more threads than that.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94