Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, November 21, 2008

Health monitoring in ASP.Net

Another good article from Mads, wish I would have known about this years ago!

Health monitoring in ASP.NET 2.0

ASP.net Performance Tuning

Here are a couple of tips on ASP.net performance tuning from an excellent article on the MSDN site

  • Tip 8—Run IIS 6.0 (If Only for Kernel Caching)
If you're not running IIS 6.0 (Windows Server™ 2003), you're missing out on some great performance enhancements in the Microsoft Web server. In Tip 7, I talked about output caching. In IIS 5.0, a request comes through IIS and then to ASP.NET. When caching is involved, an HttpModule in ASP.NET receives the request, and returns the contents from the Cache.
If you're using IIS 6.0, there is a nice little feature called kernel caching that doesn't require any code changes to ASP.NET. When a request is output-cached by ASP.NET, the IIS kernel cache receives a copy of the cached data. When a request comes from the network driver, a kernel-level driver (no context switch to user mode) receives the request, and if cached, flushes the cached data to the response, and completes execution. This means that when you use kernel-mode caching with IIS and ASP.NET output caching, you'll see unbelievable performance results. At one point during the Visual Studio 2005 development of ASP.NET, I was the program manager responsible for ASP.NET performance. The developers did the magic, but I saw all the reports on a daily basis. The kernel mode caching results were always the most interesting. The common characteristic was network saturation by requests/responses and IIS running at about five percent CPU utilization. It was amazing! There are certainly other reasons for using IIS 6.0, but kernel mode caching is an obvious one.

  • Tip 9—Use Gzip Compression
While not necessarily a server performance tip (since you might see CPU utilization go up), using gzip compression can decrease the number of bytes sent by your server. This gives the perception of faster pages and also cuts down on bandwidth usage. Depending on the data sent, how well it can be compressed, and whether the client browsers support it (IIS will only send gzip compressed content to clients that support gzip compression, such as Internet Explorer 6.0 and Firefox), your server can serve more requests per second. In fact, just about any time you can decrease the amount of data returned, you will increase requests per second.
The good news is that gzip compression is built into IIS 6.0 and is much better than the gzip compression used in IIS 5.0. Unfortunately, when attempting to turn on gzip compression in IIS 6.0, you may not be able to locate the setting on the properties dialog in IIS. The IIS team built awesome gzip capabilities into the server, but neglected to include an administrative UI for enabling it. To enable gzip compression, you have to spelunk into the innards of the XML configuration settings of IIS 6.0 (which isn't for the faint of heart). By the way, the credit goes to Scott Forsyth of OrcsWeb who helped me figure this out for the www.asp.net severs hosted by OrcsWeb.
Rather than include the procedure in this article, just read the article by Brad Wilson at IIS6 Compression. There's also a Knowledge Base article on enabling compression for ASPX, available at Enable ASPX Compression in IIS. It should be noted, however, that dynamic compression and kernel caching are mutually exclusive on IIS 6.0 due to some implementation details.

Visual Basic Functions in C#

Visual Basic functions in C# 2.0

by Mads Kristensen

Yet another great and useful article from Mads


If you used to be a VB developer, but for some reason are writing C# now, you probably miss a couple of functions. I remember being a little frustrated when I did the conversion from VB.NET to C#. It was March 2005 and I made the shift on the .NET 2.0 beta platform. I couldn’t understand why C# didn’t have some of the simplest functions like IsNumeric() and IsDate(). Also Left(), Right() and Middle() were missing. You could add a reference to the Microsoft.VisualBasic namespace, but that seemed like overkill for a few simple methods.
So I decided to make my own static class in C# 2.0 called VBFunctions that would implement exactly the four methods I was missing so much. This seems pretty basic and it is. But I use these functions again and again and now I have a single place to find them.

Prepare for growing projects

Another excellent article from one of my favorite bloggers! This article discusses items that are often missed from the start and makes our code a mess to keep up with!
Prepare for growing projects

Determine If The Current Time Falls Within a Range

This code is useful if you need to determine if the current time falls between two other times, and then execute some code or processes based on the results. This implements a user-defined function named InRange().

Declarations:
'(None)
Code:
Public Function InRange(startTime As Date, endTime As Date) As Boolean

    Dim dtNow As Date

    dtNow = Now

    Select Case TimeValue(dtNow)
        Case Is > TimeValue(startTime)
            If TimeValue(endTime) > TimeValue(dtNow) Then
                InRange = True
            End If
        Case Is > TimeValue(startTime)
            If TimeValue(endTime) > TimeValue(dtNow) Then
                InRange = True
            Else
                InRange = False
            End If
        Case Is < TimeValue(startTime) And (TimeValue(endTime) > TimeValue(dtNow))
                InRange = True
        Case Else
            InRange = False
    End Select

End Function

Private Sub Form_Load()
     Debug.Print InRange(CDate("03:00:00"), CDate("18:00:00"))
End Sub