Leaky Memory

One of the things that i am not very with is my reliance on the session state. Typically this is useful when data needs to be persisted between post backs. The down side and most over looked part of this is that depending on how the server is setup a lot of undue load can be put on the server.

I faced the full wrath of this last week Friday. The previous day , the IT team moved our web server to a new server due to the fact that we had out grown the current server. Everything had been tested on face value before the move i.e. All pages opened correctly and nothing seemed to crash spectacularly. Then on Friday , one of the pages that uses the session state started crashing with object not set to a instance exception.

I initially thought that is was a problem with the code , but nothing had changed since the previous day aside from the actual server. Next step after testing the code on a local machine and a test server was to see if other pages were doing the same thing. One or 2 other pages were giving the same error but after a post back the error disappeared.Also the local dev an test machine ran the pages fine.

Due to time constraints i did not have the opportunity to truly investigate what was wrong with the server and had to do a emergency re write of the page so that it did not reference any cache or session variables. While this proved to be a risky choice , the solution was implemented successfully and the clients were up and running again.

Now with that out of the way i started digging a bit deeper on the server side to see what was the exact problem. Unfortunately the the IT were beyond useless and i ended up doing the investigation by myself, the first port of investigation was the event log of the server. This turned out to be a dead end as all it showed was that there was null exceptions occurring on the server at the time, since i already knew this i had to look else where.

Since i was not the person that setup the actual site under IIS this was my next port of investigation as they might have just missed out a setting or 2. After checking through all the settings nothing seemed to be out of order. Since it was after hours i decided to do a few test , first while the site was running i recycled the app pool. As soon as this executed i noticed a huge memory decrease , next i executed the page that used the session state again and noticed that the memory started increasing quite drastically. While this is understandable since there are quite a few session references i got worried that the memory should not have increased that much (even taking into effect that most of the site dll’s will be loaded for the first time).

I ran the exact same test on another server and not only was the total memory usage less but it also didn’t throw any of the exceptions i had encountered. Taking a slight guess that i might just be a section of memory that the web server was have trouble accessing i decided to take a different approach on the live server.Currently the default server uses inproc memory , i decided to try and switch the server to use the ASP.net session state service.

As soon as i made the switch all the exceptions stopped appearing and the site started running smoother , so my only guess is that the inrpoc memory the the web server is using was somehow corrupted or not accessible and that by using the State Service i was able to get around this.

I would have like to have tried a server restart first , but since i dont have access to this it was out of the question.

If you have a better idea as to why i encountered these problems please leave a comment with a detailed description as number of vague answers people have given me is pretty useless.

As always never give up :)
~stalkerh

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

2 Comments to “Leaky Memory”

  1. StevenMcD 1 August 2008 at 8:15 am #

    Nice one mate, never thought of changing the session state provided. Well done mate!

  2. jameelhaffejee 1 August 2008 at 8:17 am #

    Thanks man , i would have preferred not to change it since quite a few objects can not be serialized by the ASP.net state provider but can be serialized by the inproc provider.


Leave a Reply