1

playing around with Azure IotHub, I came across the following piece of code, in the Console Sample of Iot Protocol Gateway.

// optimizing IOCP performance
int minWorkerThreads;
int minCompletionPortThreads;
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(16, minCompletionPortThreads));

At first I had no idea what IOCP is, so I looked at wikipedia for answers. it basically says that it is an API for async I/O operations on windows.

The question is, what is this piece of code actually doing, and how is it optimizing IOCP performance. The other thing is, why isn't it optimized by default, and when is it useful?

This is the repo from where I got the code

gilmishal
  • 1,884
  • 1
  • 22
  • 37
  • This code makes sure there are at least 16 IOCP processing threads, presumably so the thread pool has more of them ready at app startup. I'd say it's just a startup optimization. – Lucas Trzesniewski Sep 29 '16 at 13:34
  • 1
    ok, that makes sense. What I don't understand is why and when would you want at least 16 IOCP threads, as far as I know too many threads are a bad thing – gilmishal Sep 29 '16 at 13:39
  • You might assume he hand-tuned the value for his specific application. You however need a glass that is well over half-full and frown at completion routines that themselves are I/O bound. The default is already optimal of course. Don't use it. – Hans Passant Sep 29 '16 at 15:57

0 Answers0