I have a .Net-based website where a function gets deadlocked on the production-server. I haven’t been able to recreate the problem in development. But I have one tell-tale sign that makes it easy to detect if the deadlock has occured and that is that the number of threads is starting to increase from the “normal” 50 to above 100.
So what I’d like to do is to somehow dump information into a file when the number of threads pass 100. The information could be stacktraces, objects that run in the context of the thread etc. Anything that could lead me to the source of the problem.
I have tried to add simple logging but it was to expensive to log this in production.
Is this possible at all to do from a running site? The site is running inside IIS with .Net 3.5.
You could also try ProcDump from Microsoft which can conditionally generate a dump of a process based on the value of a performance counter such as the number of threads. Here’s an example the doc gives:
In your case you would specify “Thread Count” instead of “Handle Count” and your value would be 100 instead of 10,000.
And since you’re running is IIS I think the process name is w3wp or something similar (use that instead of “Outlook”).
Also, since this process is running managed code then you must also specify the “-ma” switch to get a full dump which is what you need to inspect a dump of a managed process.