Tech Off Thread

12 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DataSet getting corrupted in Session

Back to Forum: Tech Off
  • User profile image
    qwert231

    Ok folks, it's time for me to clean house. Here's the situation.

    Our shopping cart web app hits our database hard. We have a big database, and some screwy joins. I've gone through and tried to keep it clean, but of course there's always drag somewhere.

    One thing I did last year was store the dataset holding the cart in the session log between postbacks instead of pulling it out of the database each time.  That saved loads of database calls.

    This summer we migrated the site to .Net 2.0. I have a method that either gets the dataset out of the session, or if I tell it to, from the database. (Like after I update the database, I want to get any changes the update makes.)

    However, recently, when several users are on the system at once, datasets stored in the session are getting corrupted. They come out with missing columns, missing rows, or missing tables. Weird. (My errors say, dataset doesn't contain such-and-such.)

    I can check to make sure I have all my pieces when I pull out the dataset from the session, like do I have the number of tables or rows I expect. But what if data starts getting corrupted. I might as well be getting it out of the database then.

    I've done checks to see if I have my tables, rows and columns, and if anything looks bogus I go get a fresh copy from the database. This has reduced the errors, but made more calls to the database.

    I also make sure I do Session.Clear when the customer is done to try to free up the memory in case that's the issue... but what else am I missing?

    Any ideas?

  • User profile image
    Ang3lFir3

    while i can't begin to explain the corrupted session state without trying to look into it more myself (most likely users getting data from the wrong session or similar).... I would like to ask if you are using IIS6.0 (pretty sure its required) and State Service....

    You could add a dedicated State Server to the arena to manage the session state information for the web server(s)... This would also be beneficial if you were creating a web farm and/or using web gardening on the server(s)... (i use it with gardening on the same server)

    This could help you reduce the need to clear up any problems you might have with the web server running out of memory while managing session state.....

    Another idea is that the sessions will be lost if the appPool for the webApp is being recycled...

    Question is.... are the Session objects empty or are they just incorrect/incomplete?

    some links that might help a little:
    http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/0d9dc063-dc1a-46be-8e84-f05dbb402221.mspx?mfr=true

    http://blogs.msdn.com/david.wang/archive/2005/09/19/Why_do_I_lose_ASP_Session_State_on_IIS6.aspx

    http://msdn.microsoft.com/msdnmag/issues/04/09/WebQA/

    http://msdn.microsoft.com/msdnmag/issues/02/03/IIS6/

    hope i helped a little....

  • User profile image
    zhuo

    Hi,

    My first gut feeling is that you are solving the wrong problem. Let me reiterate the issue you are trying to solve just to make sure we are on the same page.

    You are storing shopping cart items in the database and each time a the page reloads in the shopping process, you are retrieving those shopping cart items out of the database for a particular user.

    1. Realistically if your shopping cart item is associated with an ID identifying a particular user or a particular shopping cart, and assuming that you've indexed this ID, it should not cause any performance problem at all.

    My guess is that your database schema is screwy or your query is really really screwy.

    2. What you've done by storing the shopping cart dataset in session in order to avoid frequent database access is moving the problem from being a processing issue to a memory issue. I've made an assumption here, it's based on my reasoning that if your site is generating enough traffic to cause your database to be hit hard, the same traffic would cause a large amount of data to be stored in memory. As we all know the app pool running the app gets restarted if too much memory is being used and that would surely cause you some serious usability issue under highload as user session would be cleared each time the app-pool is restarted.

    3. as someone else already suggested, more information is needed if you want a decent answer.

    James


  • User profile image
    Rossj

    qwert231 wrote:
    
    Our shopping cart web app hits our database hard. We have a big database, and some screwy joins. I've gone through and tried to keep it clean, but of course there's always drag somewhere.

    One thing I did last year was store the dataset holding the cart in the session log between postbacks instead of pulling it out of the database each time.  That saved loads of database calls.


    I am going out on a limb here and it may not be related, but could I ask how big the datasets are that you are holding in the session? I only ask because I recall a recent discussion where you mentioned sendig 90Mb of content to the browser .. and just wanted to check.

  • User profile image
    qwert231

    Rossj wrote:
     I am going out on a limb here and it may not be related, but could I ask how big the datasets are that you are holding in the session? I only ask because I recall a recent discussion where you mentioned sendig 90Mb of content to the browser .. and just wanted to check.


    True... that was a separate site app. (It was an app we use for internal stuff.) And I did put in paging, cutting down the postback to under 1Mb.

    Basically, we have a shopping cart dataset w/ 7 tables. (I'm gonna have to clean that up a bit...)
     
    I have these main tables:
    Cart (Data about the cart and customer)
    Details (Items ordered)

    I have a second Details table for a certain type of product, but it's used rarely.

    Since we're ordering images, I have a table for image data.

    Then I have a few others that have 1 record each.

    When I create the cart, or any time I add to or modify the cart, I get a fresh copy from the database, to collect any changes the database makes. When I get that fresh copy, I also put it into the session like this:
    Session("thisCart") = dsShoppingCart

    When I have a postback situation, I call my cart_Load function like this:
    dsShoppingCart = cart_Load(False) ' False signifying I don't want a fresh copy, an in memory copy is fine.

    Then, in cart_Load I do something like this:
    dsOut = Session("thisCart")
    Return dsOut

    Perhaps... I could reduce drag by doing this:
    cart_Load(False, ByRef dsShoppingCart)

    and in cart_Load this:
    dsShoppingCart = Session("thisCart")

    The cart_Load function sits in a separate class. Would I see a big performance gain this way?

    Here's a link to the code in my class that I call to load the data: http://mark.phillk.net/getCartClass.htm

  • User profile image
    figuerres

    is the web server iis6?
    is the db sql 2005 ?

    if yes to both i'd look at the sql dependancy stuff...

    it can manage data cache and keep sql hits low while letting you code as if direct to sql.

    or look at using the interfaces and base classes used by that and make your own if you have a different sql server.

    or have a "Cart Server" that is dedicated to holding the data and manages the work.

    but if you have a lot of end user traffic on an app then session on large items is not good.

    I generaly limit use of session to basic types like int, string, small arrays like no more than 10 items.

    if the items / objects are any more than a few bytes I start looking at the DB as the store not session.

    have you profiled the memory use of this app ??

  • User profile image
    qwert231

    IIS 6.0
    SQL 2005

    Maybe 25-50 users of this site.

    I think I need to get somebody in here to see what I've done. I didn't have this trouble with this code on .Net 1.1, but 2.0 is a whole lot different. I'm gonna use this to try to get my boss to get training for me.

    Don't know what to do.

  • User profile image
    qwert231

    Ok, more info on this. When we start getting these issues, the w3wp.exe is using over 150Mb in memory.

    When I'm done with the data in the session, I do this:

    Session.Clear()
    GC.Collect()


    But that doesn't seem to help. This is killing me... I think I'm reporting the symptom, but I need to trace what is eating up my memory in my code.
  • User profile image
    Ang3lFir3

    I have an application that holds that much ram often as well...... tiss not all my fault.... some of it can't really be helped... however I have it running across 4 w3wp.exe instances and sharing session through stateServer (if you have a multiprocessor box I REALLY suggest looking into webgardening ... even if it its just hyperthreaded multi processor)

    Check the properties of the AppPool the web app is running in in IIS.... make sure its not running in the defaultAppPool....

    Again this is only a guess but this is the first place i look when goofy stuff starts happening

  • User profile image
    qwert231

    Ang3lFir3 wrote:
    Check the properties of the AppPool the web app is running in in IIS.... make sure its not running in the defaultAppPool....


    It is running in default, how do I create a new AppPool?

    Edit: It was running in default. I created a new Pool, and put only it in there. Now I have 2 w3wp listed, one is fluctating, but the one for this app is holding at around 55Mb.

    I'm using Process Explorer.

  • User profile image
    figuerres

    I would comment out the GC.COllect()
    unless you have really checked that may do more harm than good.

    the GC is fairly smart -- forcing it to run may just be wasting cycles and confusing things....

  • User profile image
    qwert231

    Ang3lFir3 wrote:
    
    You could add a dedicated State Server to the arena to manage the session state information for the web server(s)... This would also be beneficial if you were creating a web farm and/or using web gardening on the server(s)... (i use it with gardening on the same server)


    Boy can things get confused. I have a whole other server, our old web server, sitting there doing NOTHING that I forgot about!

    State Server, Web Garden, I love to learn new things, especially if it will help my job.

    I have our main server (3GHz w/ 4Gb RAM), which is giving us flakey responses. It runs:
    3 Web Sites, 1 of which has about a dozen web apps and services hanging off of it. The other two are e-commerce sites we host and maintain for our customers.
    SQL 2005 for the sites
    RAID for image storage. (Right now about 300Gb free, but that will get used up between now and December.)
    EDIT: It also hosts FTP connections for users to submit their images to the raid

    The other server is less powerful, I want to say 1.6 - 1.8 GHz w/ 2Gb Ram.

    So, a couple ideas. Should I throw SQL on the second server and use it as a state server?
    Could/should I put some of the minor, less intensive web apps on the second server?
    If I should put web apps on the second server, could I put www.centurycolor.com/secure on the heftier server and www.centurycolor.com/productCatalog (which is basically just HTML) on the second server? Or do all the apps for a domain need to be on the same server?

    If you want to post links, that's fine. I'm going to go back through the links you've posted here.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.