views:

230

answers:

5

I'm embarking on a C# project where certain tasks will be divvied up and run on multiple threads. I'm looking for as many good tools as possible to help make sure I'm running as efficiently as possible. So I want to watch for things like resource (CPU) usage, blocking, deadlocks, threads that are waiting for work, and so on. I want to be able to compare different approaches to see what works best under different conditions.

I'm also looking to learn what Perfmon counters are more or less useful for trying to optimize and compare threading models.

I also can't afford to purchase anything too expensive, so the free-er the better.

This is a C# project on .NET 3.5, with VS 2008 (though I could use the VS 2010 beta if it offered more help for threading, which I've heard it does).

Thanks.

EDIT: I'm definitely looking for Perfmon recommendations, as well as any other tool that I can also use when I want to monitor the app in a production environment. So, debugging tools are needed, but I also want tools for non-debug environments. Thx.

FURTHER EDIT: Here are a few useful links I've found since I asked the question:

+3  A: 

Indeed Visual Studio 2010 is a good option: http://www.danielmoth.com/Blog/2009/05/parallel-tasks-new-visual-studio-2010.html

Konamiman
Wow. That looks great. One follow on question: does 2010 require you to "upgrade" your project from 2008 like previous VS versions did?
goheen
See here: http://stackoverflow.com/questions/916190/vs2010-and-vs2008-project-compatibility
Konamiman
You can upgrade the solutions and projects, but still target old framework versions. Multi targeting is still available.
Lex Li
+2  A: 

One "trick" that helps me when debugging threads is to remember to set each thread's name property, as it helps a lot during debugging. If the thread's Name property is not assigned, it has a null value, and the debugging window will show <No name>, so it it won't be very helpful.

luvieere
A: 

I know this is a C# question, but still : in C# you can use any CLR libraries including those written in F#. In F# there are lots of cases where concurrency becomes very easy due to its functional nature (no side effects). Maybe writing some parts in F# might pay of.

Peter
+1  A: 

Another thing i would suggest is: expose some of your classes as wmi instances. This way you can tweak settings and call functions without restarting the application, this way you can notice the effects immediately. See this article.

unclepaul84
+1  A: 

I've had the best results by creating a logger class and instrumenting my code so that I can catch when threads start and stop and measure elapsed time for their internal processes. You can also use the various .Net libs for capturing memory load as mentioned here: http://stackoverflow.com/questions/750574/how-to-get-memory-available-or-used-in-c.

I've logged to queues, databases (System.Data.Sqlite is great for this), and files. Even a cobmination queue->database with the logger on a separate thread. This has particularly helpful for multi-threaded Windows services because I can monitor the logs while its running and even control the logging verbosity through a separate control table via a small Windows app. Even the sys admins find it easy to use.

It's not that much extra work and you always have it once you deploy.

ebpower