Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do sessions use hashing?

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do sessions use hashing to organize their data?
I assume this is container-specific. I wonder if I would get a perf boost from adding hashCode method to objects that I'm putting in my sessions for Tomcat.
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have knowledge of how session attribues are implemented for any particular container, but consider that the session attribute key is always a String. So if a Hashtable/HashMap is being used to store the attributes (as I would guess is probably the case), it is the hashCode() and equals() method of the String key that would be used, not any such methods that are defined in your class.
Mark
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Tomcat and presumably other servlet engines, a session object is tracked using the sessionID (a String) as a key in a Hashtable or similar collection. Inside the session named objects are stored in a Hashtable keyed by the name (a String). This is already very efficient.
Of all the many things affecting performance in Servlets, the session mechanism is probably the least important.
The number one place to look for time wasting (IMHO) is anywhere you build up Strings and print them to the response.
(Unless you are doing JDBC queries in which case look there for time wasting).
Bill
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, sessions use Strings for keys. What was I thinking?
 
Christopher Dixon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of all the many things affecting performance in Servlets, the session mechanism is probably the least important.

I think the specifics of the in-memory mechanism itself aren't very important, but being aware of the volume/frequency of session updates by the application is critical for scalability.
It is especially important for a cluster, where agressive session persistance settings in the container config may cause modifcations to the session to persist directly to a datasource.
These concerns are probably more architectural than impementation, but everyone along the way should be aware.
JMHO,
Chris
[ April 06, 2003: Message edited by: Christopher Dixon ]
[ April 06, 2003: Message edited by: Christopher Dixon ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point Christopher.
Incidently, if you are interested in performance traps in server applications, Bitter Java by Bruce Tate makes a great read. Sort of an anti-patterns collection for web applications.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic