How to speed up your ASP.NET web application
If your web site is slow, it’s annoying to your customers. It’s annoying because nobody likes to wait: we wait all day in the physical world: in queues at the shops, at the restaurant and even on the telephone. We’re always looking for ‘faster’, because in our web consumer minds, “faster equals better”. In my personal experience as a software developer, most users share at least one principle:
Better responsiveness equals a better product
- A. Customer
If your application is simple and responsive, people will use it. If it is clunky and slow to load, people are forced to wait. Think of your application (it doesn’t matter if it’s a web or a desktop application) as a racing car. As the manufacturer of that car, you’ll want customers to come and test drive it. You’ll hope that they’ll fall in love with it after driving it, and want to buy it. If that test drive is a good experience, they’ll hopefully part with some of their hard earned cash to pay for it – and bingo, you’ve done what you needed to do: make the sale.
The same principle applies to software: if you deliver a fast, responsive application with a quick user interface, your users are more likely to think you’ve built a better product – (whether that’s right or technically wrong), because to Mr and Mrs User, a slow application is a bad one.
You can optimise your web site in just a few steps
As an ASP.NET developer, here’s a look (or a reminder) at some of the things you can look at doing before deciding it’s time to dig under the hood and start to make more fundamental changes in your application:
Disable debugging in your web.config
When you release an application in debug mode, ASP.NET forces certain files to be sent to the client with each request, instead of allowing the browser to cache them. Most people forget to switch debug mode off when they release. This creates an overhead for your server, and a longer wait for the client. Debug mode also causes other changes in your web application: think of it as a bloaty way to release because it has to include data and various hooks to allow you to debug the application that aren’t necessary in order to run it:
<compilation debug="false"/>
You’ll find the above line in your web.config file.
Enable IIS Request Compression
Request compression is a feature of Internet Information Services 6 and above that causes content to be compressed before transmission to the client, and then decompressed by the browser. Most modern browsers support this, and enabling it requires no modification to your web site at all. Do bear in mind that request compression will force your web server to work harder because it has to first compress data before sending it. This creates a small spike in CPU usage, for low to medium traffic web sites that really need a performance boost the extra CPU usage will more than likely be absorbed just fine.
In Internet Information Services 6:
- Launch IIS Manager
- Right-click the “Web Sites” node
- Click “Properties”
- Select the “Service” tab
- Tick “Compress application files” and “Compress static files”. Be sure to specify a temporary directory with sufficient free resources and consider adding a maximum limit to the temporary directory size.
- Click “Apply”
- Click “OK”
Request compression isn’t for everybody – be sure to weigh the pro’s and con’s for your particular environment.
Use page output caching
By default, IIS thinks that your ASP.NET page is dynamic. In many applications, however, not all the pages actually are. Even if they do rely on a database for content, oftentimes it’s not necessary to hit the database on each request to the page. Output caching can be enabled on a particular page by adding one line of code to the top of your ASPX file. It is a directive that informs .NET to keep a copy of the rendered page, and serve the copy (rather than the original) from disk each time it is called. This would include, for example, any database generated content from controls on the page itself, or any embedded user controls.
<%@ OutputCache Duration="10" VaryByParam="none"%>
Page output caching can be an extremely effective way to improve your web site’s performance and responsiveness. It’s a lot more flexible than I’ve explained here, and you should be aware that there are all manner of ways in which you can control the cached version of the page (for instance, you can modify the directive to have different cached versions of the page based on a URL parameter). For more information, see the MSDN documentation.
Next steps
When you’ve done these things, if your application could still use a boost, it’s time to start profiling. You’ve tried the ‘quick fixes’ – the 10 minute jobs that are more-than-likely going to make things better, but there’s always a chance the problem isn’t with your application per sé. The next step is to figure out what’s causing the problem. First identify the scope: is it limited to one user, or a bunch of users in a particular geographic region, or is it everybody? If it’s only a small bunch of people, it might be that your ISP is having routing issues and you need do nothing at all. On the other hand, you might find that everyone is affected by the issue.
In that case what you need to do is to investigate where your bottleneck is occurring. Is it your database? Is it your disks? Or is it, yes, hold on a second – more than likely it’s the things you’ve probably overlooked: your images and other media files.
Optimising your images
Many people, particularly in smaller teams, overlook image optimisation. Most image editing programs will optimise for you – and this can often reduce a file’s size anywhere between 5% and 20%, and sometimes more. With today’s media rich sites, look at what you can do to ease the burden.
Using a content delivery network
As your web site grows ever more popular, sometimes the best way to get a performance boost is to let somebody else handle delivery of your ‘resource files’ – these are your static images, scripts, movies, SWF files, etc. One option is to purchase more bandwidth from your supplier. Another is to enlist the support of a Content Delivery Network – kind of like a private, global internet with public endpoints close to your customers.
The benefit of a CDN is that you are effectively outsourcing the delivery of your static files onto another – usually much faster – network. Often this will result in an ability for your server to handle more connections than before, since it no longer has to worry about serving up the big files over and over again.
Going direct to one of the big networks can cost anywhere from about $1,000 per month upwards, but there are companies who provide full CDN integration for a fraction of the price.
Good luck with your web site optimisation and please feel free to leave comments and tips for others.
Internet Explorer banned from European version of Windows 7
“European buyers of Windows 7 will have to download and install a web browser for themselves,” according to this BBC News article, published today. “Bowing to European competition rules, Microsoft Windows 7 will ship without Internet Explorer”. ![]()
This, it would seem, is another victory for the European Commission and it’s competition rules. Microsoft has previously fallen foul of these in early 2008 when it was fined £765m by the European Commission for ‘anti-competitive behavior’: including Windows Media Player and Internet Explorer with Windows. Understandably then, it has decided to avoid that kind of financial pain again by bowing to the pressure.
Why?
Why does it matter what Microsoft choose to ship with Windows? It’s not like I have to pay for Internet Explorer, or any other browser by any other vendor, for that matter. So I, the consumer, am not losing out by it’s inclusion in the operating system.
Internet Explorer, like Windows Media Player, are features designed to make the operating system better, easier to use and increase the overall value of the product. Browsers should be features of every operating system.
Every major consumer-targeted operating system has it’s own browser included. Let’s take Apple’s Mac OS, for example: that ships with the Safari browser. Safari and IE browsers do essentially the same thing, and they are distributed to the consumer in exactly the same fashion: automatic inclusion by the vendor on to the newly purchased computer. Yet, Apple aren’t the target (so far as I know) of the EC competition rulings because they aren’t the market leader.
To impose this type of ruling on Microsoft because they are the market leader seems very similar to saying that Microsoft are the market leader because of Internet Explorer, which isn’t true at all. So surely, if you’re going to impose this type of rule on any vendor then surely you must apply it to all of them: that’s really the only way to give consumers a free, fair choice, right?
What’s the difference?
I assume that the EC are interested so much in Microsoft’s activities because it holds the majority market share. So too, then, I would assume it to be equally interested in Nokia, who according to this article, held 40.43% of the Mobile Device market share in Q12009, making them the market leader. Are Nokia the subject of an EC competition rules enquiry for bundling their own software with their device?
I can’t see much practical difference either, between companies like Dell and HP, who pre-bundle their own proprietary software programs and utilities onto the PC’s they ship, and this, either. Perhaps the EC will go after these companies under their ‘anti-competition’ rules, too.
Ultimately, it comes down to education
Eight or 9 times in 10, most users don’t care what browser they’re using: at least in my experience. Most consumers just want something that works. They don’t care what it is, why should they? I certainly don’t get all shirty when my new car comes with Michelin tyres, or Goodyear, or – who cares… they do the job.
But my point is, if I do want something different, I’m free to change those tyres. Perhaps I’ll read that Pirelli tyres are better than my Goodyears, and I’ll change them. Just as I can change my browser, any time I want to. And I don’t need the EC to make that happen for me because Microsoft haven’t prevented me from using Firefox, or any other browser, for that matter. And that’s the point: this is about education. Those who know enough to understand why they might want another browser, and can make a comparative choice, are completely free to do so, and (if I do say so myself) it is ridiculously easy to swap to an alternative.
I can’t say the same about the tyres on my car though (the ones I’ll have to pay a hefty cost to change). Thankfully, swapping my browser is free and easy. And that’s another reason why these confusing rules make me, well, confused.
It’s all down hill from here…
Now, when Windows 7 ships in Europe, what on earth will the majority of consumers do? What will Microsoft do, in order to help users make the choice that’s right for them? Will consumers see a choice of browsers pop up on their screen? How will they choose? Why should they have to choose? Does Mr And Mrs Average really care? Please comment!
Using Windows Live Writer with WordPress
Windows Live Writer is a new, free software program provided by Microsoft. The caption on the download site says: “Writer makes it easy to share your photos and videos on almost any blog service—Windows Live, WordPress, Blogger, LiveJournal, TypePad, and many more”.
“Splendid,” I thought. I’ve wanted to try Writer out, and I needed to write a new blog post as I haven’t been as faithful to my blog the past month as I’d have liked to have been. Also, as much as I like the web-based revolution, I don’t particularly find WordPress.com’s online article editor very good for much else other than writing plain-text. Inserting and uploading media is a bit of a chore, but as I found out, Writer makes that rather easy.
Without further ado, I’ll run you through the setup process here, and comment on my experiences as I go. For added authenticity, I’ll actually be writing this blog post using Live Writer. So, fingers crossed – the proof (should be) in the pudding.
Installation
Installation is straightforward, simple and easy. The Windows Live downloader includes the option to include other products within the Live suite too, including Windows Live Messenger and Movie Maker Beta.
Setup
When you run the program for the firs time, you’re asked which blogging service you use:
You then need to fill out a few other details:
And, that really is about all you need to do. Once you’ve done this, Live Writer connects to your blog, configures itself (correctly) and even downloads your blog’s CSS styles and gives you a live preview as you type. So far, so good.
The Editor
As soon as you startup after configuring your blog account, you’ll see the new editor window. It’s blank, waiting for you to write your next masterpiece:
Of particular interest here are the “Insert” links on the right-hand side of the screen:
I’ve always found the WordPress.com web editor a bit, well, clumsy. It’s clear (for sure), it’s just fiddly if you want to do anything that write text. Uploading pictures is a bit of a pain. Using Writer, I’ve simply been taking screenshots and pasting directly in to the editor window.
Rich Media Integration
Writer boasts the ability to publish your videos directly to the MSN Soapbox service, or to YouTube and then embed those videos directly into your blog. This is a really nice feature, and to test if it works, I’m going to insert a sample video here:
EDIT: As you can see, WordPress.com doesn’t seem to like the player code generated via Windows Live Writer. I’ll write to them, and ask why – and if I get a response, I’ll post it here. Shame!
Clicking on the “Video” link under “Insert” menu:
I chose “Soapbox” (as this is a service I have never used). Thankfully, there’s no registration forms to fill out. I just enter my Windows Live ID and create a ‘nickname’ for my Soapbox account:
… And that’s it. You’re then returned to the Live Writer editor and you can see your video uploading right in-place on your blog. Quite handy actually, because it meant I could carry on writing my article while the upload took place in the background.
After about 15 minutes, my video had uploaded and Soapbox had finished processing my video. The “uploading video” screen above is now replaced with:
Absolutely fantastic, so far then. So, let’s recap:
- I’ve uploaded a video to a service I’ve never used
- I didn’t have to prepare my video, I just found one and selected it
- I could carry on writing my article while uploading in the background, with the video placeholder in-line
- The video was uploaded and transcoded in around 15 minutes.
Very impressive. All I need now is some hyperlinks.
Hyperlinking
Ok, I’ve been building web pages since I was about 12. Hyperlinks are easy, right? Of course they are. But tell that to the WordPress.com editor. Linking to my previous posts has always been a pain because it doesn’t let me browse through them and pick them when creating a new link. I have to get my previous article URL and then cut and paste (somebody, please correct me if I’m wrong here – I really hope I’ve just missed this feature). Live Writer, though, does a great job:
Choosing “Previous post” then pops up the following:
Another awesome little helper-feature. Job done. Hyperlinks inserted. And I’m still in my nice WYSIWYG editor.
Summary
So, to finish up then, how would I summarise my experience using Windows Live Writer?
In a word, “brilliant”. In four words: “you should use it”.
It’s free, it’s very well built (as you’d expect), and it has a very polished interface. Microsoft have done a fantastic job here.
Arduinometer, anyone?
On Sunday, I published an article showing how I’d built an Arduino-powered ethernet gas meter, to publish real-time gas meter readings to Pachube. Thanks to James Taylor (http://twitter.com/jtonline) who re-tweeted my initial tweet highlighting it as potentially of interest to the #homecamp folks, within a few hours some 200 people had read the article, and I’ve received some great feedback and inclusion on several sites on the web. Not bad for my first article of this kind, I thought!
I’ve been thinking that I should really extend this little venture into a project that adds support for:
- Tracking electricity, gas and water meter values (all from the same Arduino), using cheap sensors
- Add support for pulse meters, as well as what I’ve dubbed ‘reflective’ meters (not sure of the proper name, but these are the meters with the little reflective discs of metal on one of the dials).
I’ve created a project on Google Code for anyone who’s interested in following (there’s not a lot there just yet, though). I’ve got a busy few weeks ahead, but will do what I can in the interim. It’s look like June will be the first real chance I have to sit down and extend the code. If anyone’s interested in getting involved, or helping out in any way, please get in touch. I’m still fairly new to the world of Arduino and physical computing, so I’m still learning too – all feedback is appreciated!

1 comment