views:

346

answers:

4

This is a pretty vague question and getting it answered seems like a long shot, but I don't know what else to do.

Ever since I made my website live every now and then it will just freeze. You click on a link and the browser will just site there looking like its trying to connect. It seems the freezing can last up to 2 minutes or so, then everything is just fine. Then a little while later, it will do the same thing.

I track all the exceptions that occur on my website in a log file.

I get these quite a bit ..

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

And the stack trace shows it leading to some method that's connecting to the database.

I'm assuming the freezing has to do with this timeout problem. My website is hosted on a shared server, and my database is on some other server with about a billion other databases as well.

But even being on a shared server, this freezing problem happens all the time. Its extremely annoying. And I can see this being a pretty catastrophic problem considering my site is ecommerce based and people are doing transactions on it. The last thing I want is the site freezing when my users hit the 'Submit payment' button, then it results in them hitting the submit payment button over and over again because the site froze, then there credit card gets charged about 10 extra times.

Does anyone have any suggestions on the best way to handle this?

+4  A: 

I am guessing that it has to do with the database connections. Check to see that they are getting released properly? If not then it will use them all up.

Also check to see if your database has connection pooling configured.

Nathan Koop
+1 improperly closed connections would be my bet too followed by analyzing queries / indexes and improving cache coverage.
Mufaka
when you run out of pool connections you get a specific error from the pool, not just a generic timeout. see http://blogs.msdn.com/angelsb/archive/2004/08/25/220333.aspx
Mauricio Scheffer
+1  A: 

The timeout errors is definitely the source of the freezing pages. When it happens the page will wait something like a minute for the database connection before it returns the error message. As the web server only handles one page at a time from each user, the entire site will seem to be frozen for the user until the timeout error comes. Even if it only happens for a few users once in a while, it will seem quite severe to them as they can't access the site at all for a minute or so.

How severe the problem really is depends on how many errors you get. From your description it sounds like you get a bit too many to be normal.

Make sure that all your data readers, command objects and connection objects gets disposed properly, so that you don't leave connections open.

Look for deadlock errors in the log also, as they can cause timeouts. If you have queries that lock each other, you may be able to improve them by changing the order that they use the tables.

Guffa
+1  A: 

Check the SQL Server logs, especially for deadlocks.

If you have multiple connections open, one might be waiting on a row that is locked by the other.

Andomar
SQL deadlocks show up as something like "System.Data.SqlClient.SqlException: Transaction (Process ID 73) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction."
Mauricio Scheffer
It will only show the deadlock error if the deadlock timeout is shorter than the query or web page timeout. That's often not the case (at least on the web sites I maintain.)
Andomar
+2  A: 

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

That's a Sql command timeout exception - it can be somewhat common if your database is under load. Make sure you're disposing of SqlConnections and SqlCommands - though that'd usually result in a pool timeout exception (can't retrieve a connection from the connection pool).

Odds are, someone is running queries that are badly tuned or otherwise sucking resources. It may be your site, but since you're on a shared db server, it could just as easily be someone else's. It could also be blocking, or open transactions - since those would be on your database, that'd be a coding issue. You'll probably need to get your hosting provider involved to track it down or move to a dedicated db server.

You can decrease the CommandTimeout of your SqlCommands - I know that sounds somewhat counter-intuitive, but I often find that it's better to fail early than try for 60 seconds throwing additional load on the server. If your .5 second query isn't done in 5 seconds, odds are it won't be done in 60 either.

Alternatively, if you're the patient type, you can increase the CommandTimeout - but there's also a IIS timeout of 90 seconds that you'll need to modify if you bump it up too much.

Mark Brackett