Re: Load Testing Errors

From: Bob Grommes (bob_at_bobgrommes.com)
Date: 12/01/04


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
cache.

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.

--Bob

"Shabam" <xxredbaronxxx@hotmail.com> wrote in message
news:5P-dnaG7w7KeBTbcRVn-pw@adelphia.com...
>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.



Relevant Pages

  • Re: c# object caching and reference counting
    ... I need to cache various resource objects such as images for example, ... (wich could be considered documents for ease of discusion) ... I realy dont want to have to keep a track of seperate reference count as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Load Testing Errors
    ... 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 ... if (someObjectKey is in the cache) { ... lower volumes, then either your cache expires very frequently, or there is ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Load Testing Errors
    ... 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 ... if (someObjectKey is in the cache) { ... lower volumes, then either your cache expires very frequently, or there is ...
    (microsoft.public.dotnet.security)
  • c# object caching and reference counting
    ... I need to cache various resource objects such as images for example, ... (wich could be considered documents for ease of discusion) ... I realy dont want to have to keep a track of seperate reference count as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: XControls: Dynamic loading & polymorphism
    ... samefoo.vi loads the wrapper VI of your choice into a subpanel. ... wrapper VI contains the XControl and outputs a reference to it. ... load foo2, ...
    (comp.lang.labview)

Loading