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.
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
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
posted 17 years ago
Yeah, sessions use Strings for keys. What was I thinking?
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 ]
Author and all-around good cowpoke
posted 17 years ago
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
Whatever you say buddy! And I believe this tiny ad too: