How to Enable IIS 6.0 Native Compression

Sun, Jul 20, 2008

1 Comment

HTTP compression can provide significant performance improvements on websites serving both static and dynamic content. The concept is simple and offers faster page downloads for the user and reduced bandwidth costs for you. Using gzip, Internet Information Services (IIS) can compress the content before it is sent from the server to compression-enabled clients.

How much compression are we talking about? Typically, I see about 70% compression on uncompressed content such as HTML, CSS, PHP, etc. Image files, which are usually already compressed, don’t benefit from HTTP compression.

IIS 5 was notoriously bad at compression, and IIS 7 (Server 2008/Vista) has it enabled by default. In the middle is IIS 6.0 on Windows Server 2003, which has great native compression built in but it’s disabled by default.

Enabling compression is not a trivial matter, nor is it overly complex, but it does take a bit of tinkering under the hood which many web admins prefer to avoid if possible. However, the benefits outway the cost so let’s do it.

Preperation

First, be prepared to restart IIS after completing these steps, so pick a good time before you begin.

We’re going to be editing the IIS metabase so we must configure IIS to allow us to save the changes. Otherwise IIS has this file locked by default. In Internet Information Services (IIS) Manager right-click on the web server and go to Properties. Tick the Enable Direct Metabase Edit checkbox like shown below then click Apply.

Enable Direct Metabase Edit

Figure 1: Enable Direct Metabase Edit

Enabling IIS Compression

Right-click on the Web Sites node in IIS Manager and go to Properties. In the Web Sites Properties dialog click the Service tab to get to the screen in Figure 2. We have a few options here but typically we’re going to go with the selected options shown. Change the Temporary directory to something else if you don’t like the default, but be certain that it’s a local NTFS partition and not marked for compression.

Enable IIS Compression

Figure 2: Enable IIS Compression

Adding the Web Service Extension

Next we’ll add the Web Service Extension in IIS Manager. Click the Web Service Extensions node and then the Add a new Web service extension link in the right pane. In the New Web Service Extension dialog box enter the name of the extension, anything you like, but most people go with HTTP Compression. Then add gzip.dll to the required files as shown in Figure 3. Your path may be different than shown here, but for most servers this is typical. Tick the Set extension status to Allowed and then click OK.

Add Web Service Extension

Figure 3: Add Web Service Extension

Editing the Metabase

We’re almost done. We just need to edit the metabase so IIS knows which file types to compress. This is a bit tricky because we must also know whether those file types are going to be static or dynamic. The issue here is that static files are going to get cached in the temporary directory whereas dynamic content is going to get compressed on every request.

The metabase is a text file located in the c:\windows\system32\inetpub\ directory. First, locate MetaBase.xml and make a backup copy in case something goes horribly wrong. Then, open MetaBase.xml in a text editor and locate the IIsCompressionScheme tag, but be careful because there are two sections here: one for deflate and one for gzip. We want the gzip section.

The tags we’re primarily interested in are:

  • HcDynamicCompressionLevel: Specifies the compression level from 1 to 10, with 10 being the highest compression level and requiring the most CPU. If your server is heavily loaded then you may want to reduce this level.
  • HcFileExtensions: Static content to compress. In the example here I’m using htm, html, txt, xml, css, and js.
  • HcScriptFileExtensions: Dynamic content to compress. In the example here I’m using asp, dll, exe, aspx, asmx, axd, and php. The axd extension is specifically for Telerik RadControls.

After we have those settings complete we can save the file.

<IIsCompressionScheme Location =”/LM/W3SVC/Filters/Compression/gzip”
HcCompressionDll=”%windir%\system32\inetsrv\gzip.dll”
HcCreateFlags=”1″
HcDoDynamicCompression=”TRUE”
HcDoOnDemandCompression=”TRUE”
HcDoStaticCompression=”TRUE”
HcDynamicCompressionLevel=”10″
HcFileExtensions=”htm
html
txt
xml
css
js”
HcOnDemandCompLevel=”10″
HcPriority=”2″
HcScriptFileExtensions=”asp
dll
exe
aspx
asmx
axd
php”
>

Fixing a Bug

There’s one more issue we need to fix before we’re done. Microsoft knowledge base article 319384 identifies a problem with “Pages do not expire as expected after you change Web site content”.

The instructions in the article say to run this command to fix the problem:

CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/Parameters/HcCacheControlHeader “max-age=0″

It doesn’t hurt to double check things because computers are stupid…

After running this command my MetaBase.xml file still contained the old setting of max-age=86400, so I just made the change manually and continued on.

Restart and Test

Now our configuration is complete. We just need to restart IIS and then test if our compression is really working. To restart IIS you can right-click the web server in IIS Manager and then click All Tasks, and then Restart IIS… Or use the iisreset /restart command if you’re a command prompt junkie.

To test if our web server is actually compressing content go to either PipeBoost or Port80 Software.

Continue reading...

3 Things to Know About WordPress on Windows/IIS

Fri, Jul 25, 2008

1 Comment

In making technology decisions I’m interested in best of bread, open source, and systems with critical mass. With that formula in mind I chose WordPress for my blogging platform. Had I known beforehand the pain that was going to be felt in using WordPress on Windows/IIS then maybe… just maybe I’d be using a different publishing system now.

Just kidding :) I love a challenge.

Here’s a list of my top 3 setup issues with WordPress and what I was able to do about of them.

ONE. This error: “%1 is not a valid Win32 application”

The generally available release of PHP, which WordPress runs on, is for 32-bit platforms only. Try to run PHP on a 64-bit Windows server and you’ll get this error. There are two fixes to this problem. Run IIS in 32-bit mode or find a 64-bit version of PHP (or build your own if you’ve got the time). The problem with running IIS in 32-bit mode is that it’s global, which means all websites on the server run in 32-bit mode.

Finding a pre-built 64-bit distribution is the route I chose. Find it here.

TWO. Pretty Permalinks

Bloggers don’t like the default web URLs for their articles in WordPress, which is something like www.aspmin.com/?p=123. With a little cosmetic help we can make the URL “pretty”. Something more like www.aspmin.com/2008/07/25/wordpress-rocks is certainly prettier than all those question marks and numbers. Especially to search engines does this look better because the pretty URL is a permanent page, a permanent link. All those letters and numbers could get the search engine into an infinite loop as it crawls the site. Pretty permalinks are SEO friendly.

The pretty permalink is not an actual path on the webserver, but is dynamically rewritten by the web server to look like it is. This is simple to do on Apache using something called mod_Rewrite. But alas there is no such thing built into Windows. I learned this while trying to change the permalink structure in WordPress. Anything other than the default question marks and numbers gives you a “404: Page Not Found” error. Does that mean Windows users are stuck with icky permalinks? Read on…

ISAPI_Rewrite is an add-on for IIS which will rewrite the URLs for us, and the Lite version is free. It’s everything we need and it doesn’t cost a thing. The website to download ISAPI_Rewrite is here.

Once ISAPI_Rewrite is installed we need to write some rules, which get stored in the httpd.ini file on the web server. It takes a bit of study to get this working correctly and I was helped by the information on this blog in getting started.

My rewrite rules are here.

THREE. The Theme Editor Doesn’t Work

The WordPress theme editor let’s you make changes to the layout of your pages, and then save those changes. Presto! Your blog has a new look. Try to save changes on a Windows server and you may get this nasty error message:

Warning: fopen(D:\Inetpub\wordpress/wp-content/themes/silver-light-01/single.php) [function.fopen]: failed to open stream: Permission denied in D:\Inetpub\wordpress\wp-admin\theme-editor.php on line 47

That’s insanity! What does it all mean?

Search the Internet you’ll find lots of advice about CHMOD, which is a UNIX permission changer. Not much about Windows. Experienced Windows users will recognize this as an NTFS permissions issue. Since my installation of WordPress isn’t in the default C:\Inetput\wwwroot location I don’t have the default NTFS permissions assigned.

The fix is to add the Internet User Guest account (something like IUSR_YOURSERVERNAME) to the WordPress installation directory with Modify permissions.

*********

Well, those are the big 3 problems I’ve hit so far, and maybe there are more to come. I hope this post can help others experiencing the same issues. Now that I have WordPress running smooth I’m thoroughly enjoying it and very thankful to the developers for making it freely available.

Continue reading...

SingleResult vs. SingleRow Performance on MySQL

Fri, Jul 25, 2008

0 Comments

We wanted to look at the performance benefits of using the various CommandBehavior options when executing queries which are expected to return a single result. It’s generally considered that the SingleResult and SingleRow options will be faster, so ASP.NET developers may simply choose these settings unconsciously. However, our benchmarks produced results much different than expected.

The database we’re evaluating is MySQL and we looked at both the MySQL Connector/Net and DevArt MyDirect.NET .NET data providers. (Please see bottom of this article for version details). Note that performance is very dependent on the data provider and how they optimize commands. Really then, what we’re evaluating here is the data provider. According to this MSDN article on SingleRow…

The query is expected to return a single row. Execution of the query may affect the database state. Some .NET Framework data providers may, but are not required to, use this information to optimize the performance of the command.

The Focus

We’re looking at a very specific and common scenario for ASP.NET developers — querying the database for a single record. We’re focusing on this very specific case to determine which setting for CommandBehavior is best to use in terms of performance.

The Results

In all cases MyDirect.NET produced faster results than Connector/NET. In addition MyDirect.NET produced expected results whereas Connector/NET gave just the opposite results of what a developer might expect when setting the CommandBehavior option.

Using MyDirect.NET, an ASP.NET developer could expect to get about 4% increase in performance using SingleResult and 35% using SingleRow. The CommandBehavior settings, especially SingleRow, can offer a significant boost with very little effort.

Connector/NET, on the other hand, is best left using the default setting. Any attempt to improve performance using CommandBehavior settings actually decreased performance, and significantly. We’re looking at a whopping 70% decrease using the SingleRow option.

SingleResult vs. SingleRow Performance

SingleResult vs. SingleRow Performance

The results here cannot be generalized and translated into a general rule which states that one .NET data provider is faster than the other. And these results certainly don’t translate to SQL Server. This is a very specific case showing that using CommandBehavior.SingleRow with DevArt MyDirect.NET is going to yield the best performance.

Disclosure:

MySQL 5.0.51b Windows x64
MySQL Connector/Net version 5.1.6
DevArt (formerly CoreLab) MyDirect.NET version 4.70.28
Windows Vista Ultimate 64-bit
.NET Framework 3.5
AMD Athlon 64 X2 6000+

Continue reading...

High Performance String Concatenation in C#

Fri, Jul 25, 2008

0 Comments

Concatenating strings in C# is easy enough to do, but as the number of strings increases, so the performance decreases. The issue is that string objects are immutable, they cannot be changed once they’re created. Therefore, to concatenate two strings requires creating a new string object rather than simply attaching one string to another in memory.

Let’s review the different ways we can concatenate strings in .NET 3.5. These are simple addition and with the help of two .NET classes, StringBuilder and String.

String Operators +=

A simple way to add two strings is with the + or += operator. To get “ASP.NET” into a string we do something like this:

String str1 = "ASP";
String str2 = "NET";
str1 += "." + str2;

This is functional but won’t offer the best performance when doing thousands of iterations or building very long strings, such as XML.

StringBuilder.Append

After a StringBuilder object is created, the Append method then is used to append string values to the object.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("ASP");
sb.Append(".");
sb.Append ("NET");
String str1 = sb.ToString();

This is more efficient than adding strings together. However, there’s a cost in creating the object and there’s going to be some initialization time involved. Thus, using StringBuilder to concatenate only two strings will actually be slower than simply adding the two together. It used to be a rule of thumb that you only used StringBuilder to concatenate ten or more strings. We’ll see later in this article if that rule still applies.

String.Concat

The String.Concat method takes up to five strings as it’s arguments and concatenates them together. This is an overloaded method, so you just add each string as an argument with the concatenated string being returned in the method call.

String str1 = "ASP";
String str2 = "NET";
String str3 = String.Concat(str1, ".", str2);

Benchmarking String Concatenation

We’d like to get some sort of rule-of-thumb to go by when writing our code. Hopefully, in this experiment we can demonstrate when to use each of the three methods discussed above.

I ran a simple benchmark to measure the number of string operations per second we could get with each method. The more operations/second the better. The results in the Figure 1 show that for concatenation of only two strings just use the + operator. When concatenating three to five strings use the String.Concat method. And for more than five strings use StringBuilder.Append.

String Concatenation Performance in .NET

Figure 1: String Concatenation Performance in .NET

Disclosure:

Windows Vista Ultimate 64-bit
.NET Framework 3.5
AMD Athlon 64 X2 6000+

Continue reading...

Top 10 Open Source Software

Tue, Jul 29, 2008

0 Comments

I’m writing this post to share some of the top open source, or otherwise free, software which I use on a daily basis to do my work. This list of top 10’s is highly subjective and really just reflects my personal preferences. I learned of these by word of mouth, googling, or reading blogs on what others are using.

1. MySQL

It’s the most popular open source database there is. Having been a long-time user of SQL Server, I was reluctant to get my feet wet with MySQL. But after suffering sticker shock at properly licensing SQL Server for use with my web servers I decided to give MySQL a try. I’m glad that I did. It’s actually become my database of choice when starting new projects.

Website: mysql.com

2. Subversion

The de-facto standard (if not already, it will be soon) for source code version control.

Website: subversion.tigris.org

3. Tortoise SVN Client

In their own words: “The coolest Interface to (Sub)Version Control”. This is a Windows shell extension which interfaces Explorer with a subversion server.

Website: tortoisesvn.net

4. VisualSVN Server

A very clean installation package and management console for Subversion server.

Website: visualsvn.com

5. WordPress

The blogging software which powers this blog. I self-host therefore pretty much have my choice of which platform to go with. Even though WordPress is not necessarily Windows friendly, runs on PHP, and so on, it it’s worth of trouble.

Website: wordpress.org

6. Eventum

Eventum (reviewed here) is a mid-range issue/bug tracking system developed by the people at MySQL and made available to the public as open source. It’s another app which runs on PHP, which is not my favorite platform to develop on, but it’s what they choose and it works fine for its intended purposes. It probably sits somewhere in the middle between Trac and OnTime in terms of features. Note: OnTime is a commercial system.

Website: eventum.mysql.org

7. FileZilla

A very good FTP client and server (although I haven’t used the server) for free. Open source and does what it needs to do.

Website: filezilla-project.org

8. ColorCop

ColorCop is a multi-purpose color picker useful for web designers and programmers. Just place the eyedropper over any area of your screen and it shows corresponding hexadecimal codes. Great for matching AdSense background colors to your website.

Website: colorcop.net

9. ISAPI_Rewrite Lite

The Lite version of this product is free and saved my bacon when trying to get WordPress to use pretty urls. This software changes, or rewrites, the URL into a different format for either aesthetics or SEO. It’s similar to Mod_rewrite in Apache.

Website: isapirewrite.com

10. FireFox

I’ve watched Internet Explorer (IE) drop from 85% usage on my website logs to nearly 60%. FireFox is the reason for that. I first started using FireFox because of the tabbed browsing and popup blocker, which Microsoft reluctantly added to IE after it was obvious FireFox was a going concern. FireFox continues to deliver what users want and when they stop doing that I’ll switch back to IE.

Website: mozilla.com/firefox

*********

Continue reading...

Using the C# ?? Null Coalescing Operator

Sat, Jul 26, 2008

0 Comments

SQL users are familiar with the COALESCE function, which is great for assigning values and building WHERE clauses. It’d be cool to have a similar capability in C#. Our code would be more compact, easier to write (forget all those if-then-else statements), and easier to maintain. Welcome the ?? ‘null coalescing’ operator.

Simply put, the ?? operator takes the first non-null value in the arguments evaluated from left to right. If the left argument is not null then it’s used and the right argmument is ignored. If the left argument is null then the right argument is used.

The systax goes like this:

string name = "ASPmin Blog";
string result = name ?? "Name not found";
// Outcome: result == "ASPmin Blog"

If, on the other hand, the left argument is null we’ll get a different result:

string name = null;
string result = name ?? "Name not found";
// Outcome: result == "Name not found"

That’s cool, but what about value types which can’t be null? Simple, we just use a nullable type like this:

int? id = null;
int result = id ?? 0;
// Outcome: result == 0

Using ? after int makes it nullable, which is actually a shorthand form of System.Nullable<int>.

There we have a nice way to keep our code looking nice and shorten our development time.

Continue reading...

How to Add FreeHitMaps to WordPress

Sun, Jul 27, 2008

2 Comments

Most bloggers like to have a hit counter of some sort on their blog. It shows to the public the popularity of their posts and sometimes provides a means of collecting visitor stats.

FreeHitMaps is such a counter. It’s more like a 2-D hit counter because it adds the dimension of location. And besides, it just looks prettier than a bank of numbers on your sidebar. Sounds great! So how do I get a hit map onto my WordPress blog?

It’s very easy, really. Just go to FreeHitMaps.com and make a map (signup required). There are many options to choose from when making the map, but the most important are style and size. For example, a lot of blogs run a 160 pixel width sidebar, so you’d size the map for 160 pixels width. It’ll drop right into your sidebar nicely.

After you make the map, get the code and copy it into a WordPress Text widget for your sidebar. Since I’m a WordPress newbie I can’t say which versions of WordPress this technique will work on, but I’m using WordPress 2.6.

A really nice feature is that you can change the style, or size, or any other options after you’ve made the map. And since the map code is all HTML and not JavaScript it’ll go just about anywhere.

You've been marked on my visitor map!
Continue reading...

How to Add PayPal Donate Buttons using Master Pages

Sun, Jul 27, 2008

0 Comments

The Master Pages feature of ASP.NET is great for maintaining a consistent look on your website. However, try to add a PayPal donate button to a child page and you’ll quickly hit a wall built into the Master Pages architecture. That wall, the source of our problem, is the <form /> tag on the master page.

The code provided by PayPal also contains the <form /> tag. By adding the PayPal donate button code to a child page we in effect create nested <form /> tags, which is a no-no.

What to do?

One workaround to this problem is to put the entire PayPal code snippet into an <iframe /> on the child page. The PayPal code actually goes into a separate HTML file and then we embed that onto our child page using the <iframe /> tag.

The iframe code for our child page:

<iframe frameborder="0" src="paypal.htm"></iframe>

The paypal.htm HTML file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Donate</title>
</head>
<body style="padding:0px; margin:0px;">
    <form name="_xclick" method="post" target="_top"
action="https://www.paypal.com/us/cgi-bin/webscr">
        <input type="hidden" name="cmd" value="_xclick" />
        <input type="hidden" name="item_name" value="Donation" />
        <input type="hidden" name="currency_code" value="USD" />
        <input src="http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif"
type="image" border="0" name="submit"
alt="Make payments with PayPal - it's fast, free and secure!" />
    </form>
</body>
</html>

*********
Happy clicks!

Continue reading...

How to Take an ASP.NET Website Offline

Sun, Jul 27, 2008

0 Comments

How do you take and ASP.NET website offline?

It’s dead simple…

Just drop a file called App_Offline.htm into your root directory. It doesn’t need to contain anything, but you might want to write a friendly “Down for Maintenance note”, such as this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Application Offline</title>
    <style type="text/css">
        div {
            background-color:#ffffcc;
            padding-top:10px;
            padding-bottom:10px;
            padding-left:10px;
            padding-right:10px;
            border-style:solid;
            border-color:Black;
            border-width:1px;
        }
    </style>
</head>
<body>
<div>Please note that the website your are currently trying to visit is
temporarily down for maintenance, the website will be back online as soon
as possible.</div>
</body>
</html>
Continue reading...

Eventum on ASP.NET, a Free Alternative to OnTime

Mon, Jul 28, 2008

0 Comments

OnTime is a popular product used to track bugs and support issues, and also includes some project management features. In evaluating bug tracking software for a company to deploy in their IT department I at first recommended OnTime because of its very professional polish. There’s no company I know of which is so aggressively going after the bug tracking software market. However, OnTime is a commercial product so we were looking at thousands of dollars at a time when companies are paring budgets. Enter Eventum — a free, open source bug tracking solution developed by the people at MySQL. Is it a good enough alternative to an expensive commercial system?

In their own words:

Eventum is a user-friendly and flexible issue tracking system that can be used by a support department to track incoming technical support requests, or by a software development team to quickly organize tasks and bugs.

Eventum will run on ASP.NET but its roots are in Apache and PHP. But not to worry. I found the installation to be very straightforward, basic really. Actually, the only difficulty was in getting PHP installed and working with IIS. Once that step is completed getting Eventum up and running is a snap. You just copy the distribution files into a folder and launch a browser. Eventum automatically detects that it’s a new install and walks you through setting up your database.

MySQL is your only option for the database. This may be a blocking issue for some shops and for others a welcome relief to expensive SQL Server licences.

I did hit a setup issue with Eventum which required changing a MySQL setting before I could proceed. The SQL Mode setting of STRICT_TRANS_TABLE had to be removed. It’s a default setting in MySQL 5 which requires a default value for blob/text fields. After that setting was made it was smooth sailing.

Once Eventum is up and running you see a rather plain looking UI. Nothing compared to the fancy graphics and button overload of OnTime. But really, we’re talking about bug tracking here. Do we need bells and whistles? I think not. About 30 minutes of getting familiar with the system was all it took to start using Eventum for tracking bugs.

There’s a seperate component for managing the email queue. No email is sent out directly by Eventum but rather gets processed through a queuing system. The mail queue manager is a seperate application which gets fired by a Windows scheduled task every minute, 5 minutes, or whatever you wish. I created a schedule task with 5 minute intervals because I didn’t want one instance to fire while another was still running. This will produce an ugly locked file situation which has to be manually fixed. It’s an entirely manual process of setting this up and not nearly as slick as setting up Eventum. But once it’s finished you can forget about it as it processes emails in the backgournd.

Beyond some minor setup issues, is Eventum a viable alternative to commercial bug tracking software? We think so, but it may not be right for everybody. There are different technology and support decisions to be made, and it may not fit the group’s software development methods. If it might be a good fit for your organization it’s worth a test-drive, anyways.

Footnote: Be sure to enable IIS compression. It significantly improves the performance of Eventum.

Continue reading...
Older Entries