Sunday, 16 March 2008

trouble shooting slow web site

What are the common mistakes causing your (1.1) site to run slowly? (pages take ages to load) Is there some kind of check list (urls) I can look at, are there any tools to diagnose this?

There isn't really a magic checklist - somewhere along the way something is running too slowly: reading from database, doing business logic, generating pages, sending over the network, rendering in the browser...

The poor man's tool (which always works well for me): strategically place code throughout the application that logs timestamps, look at where the time is being used and drill down into that area with more fine-grained logging. You can usually zoom in on the problem area quickly and then apply performance tuning techniques appropriately (e.g. examine database query plans, etc).

The first time it runs any page on the site, it has to load all the dlls. So if you have a low-usage site, you're going to have that happen a lot.

Check the properties of the pages. If you have a large viewstate, then every page will take forever on slow connections (I have seen 300kb in viewstate on a page). If viewstate is part of the problem, then you should look into storing the state serverside. There should be a bunch of articles on the web about how to do that. Viewstate will be stored as a hidden input field on the page:

To solve a bad query (which I was not permitted to fix), on one slow loading page, we set up the server to cache that page specially, so it really ran only like once/day, and was fed from the cache the rest of the time.

One thing that got a site that I worked on to go faster was that someone had the include for the CSS in the code of the page by accident. Moving that to the header speed up teh pages dramatically. It was actually acceptable using dialup and before it wasn't.

I'd look for ViewState bloat first. View the source of the page from your web browser. If ViewState is a problem, it'll be very obvious from pages and pages of seemingly random garbage.

Then I'd look for excess use of DataBinder.Eval (or the newer Eval and Bind methods in ASP.NET 2.0). DataBinder.Eval late binds using reflection which means it's sloooooooow. You can get tremendous performance gains by dumping DataBinder.Eval in favor of direct casting of the data item to the appropriate type.

Be sure to eliminate the obvious stuff first. Like dozens of connections to download objects, and large file size and image size.

You can use a tool like to check some of this.

Once you know it's not that, then start in on the advice given above.

Log4Net is a good tool to do logging of timestamps. You can turn it on/off with the config file, so you can use the same code and never mess with multiple compiles. …

If it is "slow" it should be easy to "shoot". ;)

Sorry, I couldn't resist making fun of the title of this post. I think he meant "troubleshooting" huh?

No comments: