Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance with cookies

 
Venkatraman Kandaswamy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People, here is the issue. We already have a bloated session. Anything and everything is being put on the session.

I have this new requirement where I have to show a drop down in every page of the application. The values of the drop down are populated by a costly database call. I can solve easily by putting the drop down values ( say a hashmap of id-name pairs ) in session and go home happily. However I was thinking of other options and cookies came to my mind.

Having cookies turned on is a requirement in our project so I need not worry about the what-if scenario when cookies get turned off.

So how big a performance hit will it be if I use cookies to offload the drop down values and show it in every page?

I spoke to my developer friends who have worked in a lot of projects and they say generally most of the projects do not use cookies mostly and if at all they use, its used very sparingly, like saving the account name for instance.


Thanks folks
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can the values be placed in a shared cache for all to use and not in the session object?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you do, the cookies are just used to identify the user and get the correct session - so whatever you put into the session, the cookie will always look the same. Putting big objects into the session won't have any performance impacts on the application, as long as you don't get memory problems.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that cookie values end up being transmitted with every request so they will add to the request processing overhead. There is no reason to be concerned with this unless you actually get memory problems.
Bill
 
Venkatraman Kandaswamy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks. Like your suggestions we have decided to go the session route - security hats are a little paranoid of putting such stuff in cookie - and also as William said so far we have had no memory complaints. Also at the same time we are thinking of looking into the stuff we put in session to make sure we dont get memory problems in future.

Thanks once again for the great comments.
 
Avianu Sud
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this data is common across all users, put it in the Application Scope or even as a static Hash. Putting the same info for all sessions is a huge overhead.

If its specific to a user, thats a different story.

Good luck,
Avi
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting the same info for all sessions is a huge overhead.

That would only be true if each session got a separate copy OR the sessions are being serialized - if the objects are shared in the application then all session references will point to the same set of objects. For objects that have no user specific data, Application scope is the place.
Bill
[ October 07, 2005: Message edited by: William Brogden ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic