File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Performance with cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Performance with cookies" Watch "Performance with cookies" New topic
Author

Performance with cookies

Venkatraman Kandaswamy
Ranch Hand

Joined: Jul 07, 2004
Posts: 120
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


--Venkatraman<br />SCJP 1.4<br /><a href="http://kvrlogs.blogspot.com" target="_blank" rel="nofollow">blog</a>
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
Can the values be placed in a shared cache for all to use and not in the session object?


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
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

Joined: Jul 07, 2004
Posts: 120
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

Joined: Jan 20, 2002
Posts: 55
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

Joined: Mar 22, 2000
Posts: 12681
    
    5
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Performance with cookies
 
Similar Threads
Session handling in servlets
Drop down in jsp
Too many drop down lists in my page
Drop Down Box in Struts - Select Default Value Implementation
saving session variable in drop down list