开发者

Site dies after so long?

开发者 https://www.devze.com 2023-04-07 11:29 出处:网络
I have a website doing some things that I\'ve never seen before. My server is Win 2003 w/ IIS6 I\'m using C# and .Net 4.0.

I have a website doing some things that I've never seen before. My server is Win 2003 w/ IIS6 I'm using C# and .Net 4.0.

The site is a real-estate website that stores the data directly in my db. The site will run great for a little while and then just die. What I mean is you'll try to view a property's details and it will take the site 开发者_JAVA百科2-3 minutes to load, if it loads at all. If I simply resave the web.config file and reupload it to restart the app, it runs just fine for a little while and then will die again. This continues over and over. I've gone to the local copy while the live site has "died" and the local copy will run just fine and then it will die after so long as well. The time frame that it takes varies from 5 minutes to 30 minutes, i believe it has something to do with the number of requests.

Anyone have any clue as to what might be happening? The only the data query on the page is to pull the main data which is the LINQ query below:

public Listing GetListingByMLNumber(string MLNumber)
{
    try
    {
        DatabaseDataContext db = new DatabaseDataContext();
        var item = (from a in db.Listings
                    where a.ML_.ToLower() == MLNumber.ToLower()
                    select a).FirstOrDefault();

        return item;
    }
    catch (Exception ex)
    {
        Message = ex.Message;
        return null;
    }
}


Not closing the database context stands out as the obvious error in the code you provided. Wrap it in a using statement to be sure it gets disposed correctly.

As long as the context lives, you will hold on to a sql connection, which is a limited resource. You will also waste memory by change-tracking the entities you returned. Given your code the context should be garbage collected at some point, but it might still be the problem (And, whether or not this is the problem, you should dispose your database contexts).

Try load testing locally to see if you can reproduce the problem. If you can, then use the debugger to figure out the problem. If not, you probably need to add logging to narrow down the problem.

You could also look at the IIS process to see if it uses absurd amounts of memory, handles, etc. Also check IIS settings for performance and application pool recyling as suggested in another answer here.


I would take a look at the application pool settings to see how the worker processes are being recycled, and I would also look under the Performance tab in IIS to see if there's a bandwidth threshold specified.


If you ever hit this type of problem again then your should add DebugDiag/ADPlus and WinDBG to your diagnostic toolbelt.

When your application hangs again or is taking an exceedingly long time to respond to requests then grab a dump of the worker process using DebugDiag or ADPlus. Load this up into WinDBG, load up SOS (Son of Strike) which is a WinDBG extension for managed code debugging and start digging around.

Tess Ferrandez has a great set of tutorials and labs on how to use these tools effectively:

.NET Debugging Demos - Information and setup instructions

They've gotten me out of a few pickles several times and it's well worth spending the time familiarising yourself with them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号