Session variables or cookies?

Results 1 to 4 of 4

Thread: Session variables or cookies?

  1. #1
    Quasibuddha Guest

    Default Session variables or cookies?

    If i have two pieces of information specific to each user on the site, should i use cookies or the Session Object ?<BR>What i would like to know is that is there any performance improvement in using cookies against Session variables?<BR>Since there is some processing involved in accesssing session variables as against cookies, i would think there would be.<BR>your comments?

  2. #2
    Join Date
    Dec 1969

    Default RE: Session variables or cookies?

    I would expect that session variables would be faster because you don&#039t have to request data from across the internet. Think about what happens when you request data from a cookie. Your server sends a message requesting the cookie to the client, the clients box processes that request and then sends it back to your web server, and then your web server still has to process the data that was returned.<BR><BR>However, I have used both these methods and have never had a performance issue with either, especially when the amount of data stored in the variable is small. There are scalability issues when considering the user of session variables though. If you are planning for expotnential growth you may want to keep session variabbles to a minimum. You should also consider what happens an end user doesn&#039t allow you to set a cookie, either temporary or permanent. There are many other ways of maintaining state, as well as reatining data with the user. There is a cost to developing this type of application though and a cost-benefit analysis is recomended. <BR><BR>But back to performance... If the amount of data is small and you rarley see 500 people on application at anyone time, assuming you have an ample web server with a reasonable amount of memory, session variables are fine because of their ease of use. However, if you have an extremely active site and speed is a critical concern and the data is small enough, I would pass the data via the querystring. My management believes that our customers (we deal with scientists) do not like having cookies set on their boxes (many of them have them turned off) and therefore the querystring is a wonderful way for me to transer data quickly without using too many server

  3. #3
    SPG Guest

    Default Additional Info + correction

    There are no extra round-trips introduced with cookies. All cookies which are relevant to a URL are sent as part of the request for the URL. The overhead for cookies comes in when the server opens up dynamic storage for them and then files and references them as an unordered collection at run-time.<BR><BR>Sessions operate on cookies. The session sends the client a UID cookie which points back to a specific session collection (which stays server side).<BR><BR>So, the comparison is as follows:<BR>1) Sessions take less bandwidth to transmit for larger quantites of data, as they only transmit the UID.<BR>2) Sessions take more server resources for larger quantites of data because they keep everything to themselves, only worrying the user with the UID.<BR>3) To minimize the scalability issues with 3, sessions will time out if left unattended -- which may cause grief to your users. You can define when cookies will "time out," thus avoiding such issues. <BR>4) Cookies will also survive an "instability" in service (because they&#039re client side) -- sessions, generally, will not.<BR>5) Cookies may have flux problems depending on how a user has their cookies set and requests your pages (ie: they can get lost in the shuffle). Although this is becoming decreasingly likely, the possibility is there. This probably isn&#039t possible with sessions.<BR>6) Both conventional sessions and cookies require the passive consent of the user in order to function proprly (as Bart covered).<BR><BR>On my intranet project, I use client side cookies with no termination set -- these are, confusingly enough, refered to as "session cookies" and are removed when the user ends their session by closing their browser. Hence, they can go to lunch, come back, and pick up where they left off. They like that. It doesn&#039t do bad things to the server. I like that.<BR><BR>HiH

  4. #4
    Join Date
    Dec 1969

    Default RE: Additional Info + correction

    hey thanks for catching my screw up about the round trip to client for retrieving cookie data!<BR><BR>bart

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts