Practical Concurrency Patterns: Lock-Free Operations

July 30, 2008

In the previous installments we have reviewed multiple strategies for caching or storing calculated key-value data so that accesses to it are optimized to the highest applicable degree.  For simpler storage types, such as a work item queue, there are even cheaper alternatives that what we've seen so far. Consider the following scenario: A stock trade application receives trade orders at the alarming rate of thousands of operations per second from multiple sources Orders are placed in a queue for further processing in order to free the front-end component(s) Orders are removed from the queue by...

Guaranteed, Finalization Order Is Not

July 28, 2008

As part of our ongoing quest to categorize all finalization-related problems, I'd like to present another honorable mention in the series.  This time, it's finalization order (or the lack thereof). A quick refresher on finalization: When an object with a finalizer is created, a reference to it is placed in the finalization queue.  When the object is no longer referenced by the application, the GC moves it to the f-reachable queue.  This wakes up the finalizer thread, which in turn removes the object from the queue and runs its finalizer.  At the next GC, the object's memory is...

Finalizer vs. Application: A Race Condition from Hell

One of my favorite managed debugging demos is analyzing a memory leak caused by a blocking finalizer.  This tension between the finalizer thread and the application threads making allocations should be kept in mind by any programmer using this powerful but dangerous feature.  However, there is another subtle category of bugs that can surface "thanks" to finalization: Race conditions between the finalizer and your application threads. For example, consider the following scenario in which the File class acts as a wrapper over an implementation-provided Handle type: class File : IDisposable {     Handle h;       public File(string...

Exposing Custom Performance Counters in .NET

July 19, 2008

One of the first things I do as part of the .NET Performance course is demonstrating some of the ways we have for measuring the performance of individual applications and of the system as a whole. As part of that quest, we encounter tools that require no ad-hoc participation on our part: Fire them up, give them an executable or a process to do their magic, and analyze the results.  Some other tools need more love and care on our part to produce anything remotely useful. A profiler can tell you that you're spending 90% of the time in...

AppDomains and Remoting Life-Time Service

Sometimes we forget that .NET AppDomains are really separate light-weight processes inside a single .NET process.  We enjoy all the benefits of a light-weight process: fault isolation, assembly "unloading", custom security policies, and many other things. But we often forget that AppDomains are separate from their host and from each other, and that under the covers they use good old .NET Remoting to communicate.  With that in mind, perhaps you can answer the following question: I'm creating an object in a separate AppDomain and storing a reference to it in a dictionary.  At some point, when I'm trying...

Sela Technology Center Course: .NET Performance, Internals and Debugging

July 16, 2008

Yesterday was the second session in our series of courses for our instructors and consultants.  It was my turn to be the lecturer, and I talked about performance measurement on Windows in general and using .NET in particular. In a pretty standard but significantly faster-paced session taken from the .NET Performance course, I've reviewed the CLR Profiler, the Visual Studio 2008 Profiler, performance counters as well as exposing your own performance counters, querying WMI information (I've also mentioned how to expose WMI information), and demonstrated my own tool that I developed for the course - called "Performance Harness" -...
no comments

Deadlock In Traffic

July 14, 2008

No, I'm not talking about deadlocks resulting from high traffic on an IIS server.  I'm talking about a real-world physical deadlock involving cars that I've been part of today.  I didn't even need Wait Chain Traversal - it was the perfect visualization, quotable for books and articles. It was one of the most amusing things I've ever seen.  Consider the two-way (right-hand driving) street depicted in the diagram.  Car A has just emerged from a parking lot on the right hand side, and is waiting for the left lane of cars to clear.  Car B has simultaneously...

Is It a Managed or a Native Memory Leak?

July 13, 2008

How do you determine whether the memory issue you seem to be experiencing is a .NET memory leak or a native memory leak?  Why is it even important? It's the first question I as a consultant would ask you if we were to talk over the phone regarding a high-memory problem you've having.  It's extremely important because in most of the cases it narrows the scope of the problem and facilitates bringing the appropriate people, tools and resources for focusing on the task at hand. The process for diagnosing a .NET memory leak revolves around tools such as the...

Interview Questions Considered Harmful: A Sequel

July 12, 2008

I've come up with two additional categories of interview questions after having incorporated some feedback on my earlier post from colleagues and friends.  Hopefully this list won't grow any longer than it is... Impossible Technical Questions With a pen and paper, provide an implementation that would automatically normalize a database representation, generate the appropriate constraints and index tables based on SQL profiling information from runtime. Yes, it's a great idea and one the interviewer might be considering for a future startup, but it's not practical to expect anything practical in an interview.  You might discuss the design of this...

Sharing WCF Contracts as Visual Studio File Links

There are multiple ways of sharing WCF contract types across service boundaries.  The recommended way, which I have no intent of undermining, is sharing contracts via service metadata.  This means that the contract CLR types can be private (internal) to the service, and regenerated on the consumer's side from the service metadata. This provides full decoupling between the service and its consumers, guarantees that there is no dependency on CLR-specific information that can't be conveyed in an interoperable fashion, and ensures that only contractual information is shared.  For example, a method declared on a data contract type...
tags: ,
one comment