Signup Login
Try it for FREE!

Improving .NET Application Performance Part 6: Threading

This post is a part of a series of posts on .NET Application performance. The first five articles are also available on our blog: Part 1Part2 ; Part 3 ; part 4 ; part5

In our last article we discussed some guidelines to optimize Garbage Collection using the Dispose and Finalize methods. In this article we’ll look at best practices for using threading. The .NET Framework offers various threading and synchronization features. Using multiple threads can and will impact application performance and scalability.

Managed Threads and Operating System Threads

The CLR exposes managed threads, which are different from the Win32 threads. The logical thread is the managed version of a thread, while the Win32 thread is the physical thread that actually executes code. If you create a managed thread object and then do not start it by calling its Start method, a new Win32 thread is not created. When a managed thread is terminated or it completes, the underlying Win32 thread is destroyed. The Thread object is cleaned up only during garbage collection.

Be aware that poorly-written multithreaded code can lead to various problems including deadlocks, race conditions, thread starvation, and thread affinity. All of these can impact application performance, scalability, resilience, and correctness.
Read the full post

Category: Application Performance Management, Articles

Improving .NET Application Performance Part 5: Finalize and Dispose

In our last article we discussed some guidelines to optimize Garbage Collection. The garbage collector provides two more additional methods; Finalize and Dispose. We’ll discuss the guidelines for these methods in this article.

Finalize

Some objects require additional cleanup because they use unmanaged resources that need to be released. This is handled by finalization. An object registers for finalization by overriding the Object.Finalize method.

An object’s Finalize method is called before the object’s managed memory is reclaimed. This allows you to release any unmanaged resources that are maintained by the object. If you implement Finalize, you cannot control when this method should be called because this is left to the garbage collector.

The finalization process requires a minimum of two collection cycles to fully release the object’s memory. During the first collection pass, the object is marked for finalization. Finalization runs on a specialized thread that is independent from the garbage collector. After finalization occurs, the garbage collector can reclaim the object’s memory.
Read the full post

Category: Application Performance Management, Articles

Improving .NET Application Performance Part 4: Garbage Collection

This post is a part of a series of posts on .NET Application performance. The first three articles are also available on our blog: Part 1Part2 ; Part 3

In this article of our series on improving .NET application performance and in this article we’ll discuss garbage collection guidelines. The .NET Framework uses automatic garbage collection to manage memory for all applications. When you use the New operator to create an object, the object’s memory is obtained from the managed heap. When the garbage collector decides that sufficient garbage has accumulated that it is efficient to do so, it performs a collection to free some memory. This process is fully automatic, but there are a number of things you need to be aware of.

Let’s take a look at the lifecycle of a managed object:

  1. Memory for an object is allocated from the managed heap when you call new. The object’s constructor is called after the memory is allocated.
  2. The object is used for a period of time.
  3. The object dies due to all its references either being explicitly set to null or else going out of scope.
  4. The object’s memory is freed (collected) some time later. After the memory is freed, it is generally available for other objects to use again.
    Read the full post
Category: Application Performance Management

Improving .NET Application Performance Part 3: Class Design Considerations

In this third article of our series on improving .NET application performance and in this article we’ll discuss various techniques to optimize and improve the performance of your managed code. Most importantly; class design, memory management and garbage collection, efficient multithreading, effective asynchronous execution, boxing, and exception handling. 

As you are well aware, the way you write your managed code can either take full advantage of the common language runtime (CLR) high performance features, or it can hinder it. We will point out the most important performance-related issues that help avoid common mistakes and hopefully help you to improve the performance of your code.  In this article we’ll focus on class design considerations and have listed the most important ones below.

Avoid making classes thread safe by default – Consider if it is necessary to make your class thread safe as it is often only necessary at a higher layer and not a the individual class level.

Use the sealed keyword – If you don’t need or want to extend your base classes, consider marking them with the ‘sealed’ keyword. If you derive a class from a base class with virtual members and want to prevent further extensibility of the derived class, use the ‘sealed’ keyword with the virtual members of your derived class. Sealing virtual methods allows for inlining and other compiler optimizations.

Read the full post

Category: Application Performance Management, Articles

Improving .NET Application Performance Part 2: Application Engineering and Design Considerations

This is the second article in our series on improving .NET application performance and in this article we’ll focus on the upfront phase of the development process, looking at design considerations.

In our introduction article we touched on setting performance objectives so you have something to measure and compare against. Ask questions like; How fast is fast enough? What are your time and throughput constraints? How much CPU, memory, disk and network I/O is acceptable for your application to utilize? These are important items that your design should be able to accommodate.

In this article we’ll describe a number of design principles that will help design application that meet the performance objectives that you have defined.
Read the full post

Category: Application Performance Management

Trusted by:

trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by
About Monitis

Monitis GFI is a specialist provider of web and Cloud monitoring services that include website monitoring, site load testing, transaction monitoring, application and database monitoring, Cloud resource monitoring, and server and internal network monitoring within one easy-to-use dashboard. Over 100,000 users worldwide have chosen Monitis as their provider of choice to increase uptime and user experience of their services and products. What makes Monitis' solutions different is that they are fast to deploy, feature-rich in technology and provide a comprehensive single-pane view of on-premise and off-premise infrastructure and applications.

Follow Monitis on Facebook
Follow Monitis on Twitter