Re: Load Testing Errors

From: Bob Grommes (
Date: 12/01/04

  • Next message: Dathon: "How to check if dynamically loaded assembly is yours?"
    Date: Wed, 1 Dec 2004 15:32:51 -0700

    Another thing to check when you get null reference errors in an ASP.NET
    application, but ONLY under load, is whether the objects on which you're
    getting the null reference exceptions are in any way retreived from the

    The following seemingly innocuous pseudo code can work fine until the site
    is under stress:

    if (someObjectKey is in the cache) {
      // Following line can give null reference exception under load
      Get the Object by key and do something with it
    } else {
      Create new object and put it in the cache

    The reason is that there is an outside chance that between the if test and
    the retreival, the object will expire in the cache. And the busier the site
    is, the more often it will happen.

    The following code avoids this issue:

    myType myReference = theCache(keyValue);

    if (myReference == null) {
        Create new object and put it into the cache
    } else {
       use the object via myReference

    If the object isn't in the cache you'll get a null reference and can check
    for it; if it IS in the cache you'll get the desired object. If the object
    expires in the cache before you get to use it, there's no problem because
    you got your reference before that happened.

    Generally the failure rate for the above problem code is very low, just a
    tiny fraction of a percent of the time -- < 10 times out of 250K page views
    would be typical. If the failure rate is higher than that, especially at
    lower volumes, then either your cache expires very frequently, or there is
    some other issue to look for.

    I mention this only because it is a hard bug to reproduce and even harder to
    figure out, yet it's easy to prevent.


    "Shabam" <> wrote in message
    >A web application of mine developed using C# + MS SQL runs fine normally.
    > However when I stress test it with a load testing software (using about 60
    > simultaneous users) some instances start erroring out. I see two
    > different
    > errors. One is a "Object reference not set to an instance of an object."
    > error, which appears to always contain the same information, and the other
    > is a "There is no row at position X.", where X is a number.
    > Is this an indication of bad coding or is this just a normal consequence
    > of
    > overloading a web application? How can the above two errors happen when
    > the
    > server is being overloaded when normally the application works fine?
    > ERROR #1:
    > Server Error in '/' Application.
    > ----------------------------------------------------------------------------
    > ----
    > Object reference not set to an instance of an object.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.

  • Next message: Dathon: "How to check if dynamically loaded assembly is yours?"