开发者

Tools, tips, and tricks for monitoring multithreaded .NET applications

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 t开发者_如何学Pythonhe 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:

  • Tools And Techniques to Identify Concurrency Issues (MSDN Magazine Article)
  • PerfMon - Your debugging buddy (important counters for .NET debugging, including threading related counters)


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


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.


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: 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜