6

I am currently converting a database stored procedure call to be asynchronous, leveraging async/await. Similar to the method described here.

Based on this answer, I'd like to verify that asynchronous call is actually using I/O completion ports. If it's ultimately waiting on another thread from the ThreadPool, then it is effectively defeating the purpose of converting the call.

What is the best way to verify that an I/O completion port is being used and it's not simply blocking on another thread?

Community
  • 1
  • 1
CodeNaked
  • 40,753
  • 6
  • 122
  • 148

2 Answers2

3

Invoke WAITFOR DELAY '1:00:00' 1000 times in parallel. If far less than 1000 threads are being used, you are getting threadless IO. You should see a few dozens (which includes lots of utility threads started by runtimes and frameworks).

You can also break with the debugger and make sure that no thread is currently waiting for IO. You can tell from the stack trace. This works with any existing application.

usr
  • 168,620
  • 35
  • 240
  • 369
  • I have a feeling this might be the most definitive answer. I'd have to tweak the connection pool limits to ensure all 1000 execute, but since it's just a test that should be fine. – CodeNaked Sep 11 '13 at 15:20
0

I would create some perfmon counters and update them in the thread pool threads. Then you can watch the app being used, and see how many threads are in-use at any given time, which in turn might help you tune the number. You could also log the time each thread took, and count that too so you can see the average wait time, this would help you determine if they were getting blocked, though I think the number of threads would show that too - in that you'd see several complete at once if they were waiting on each other. Depends on the work you're doing.

I did this years ago for a web app, it was very informative to performance tuning the app.

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
  • How can I "update them in the thread pool threads"? I'm not aware of any hooks related to the threads? Keep in mind that I'm not creating the potential thread, or really the code that it would execute. I would just be using `BeginExecuteReader`, which has the potential to block a ThreadPool thread if it's not configure perfectly. – CodeNaked Sep 11 '13 at 15:17