I think the bottom line here is that if you're concerned about performance,
database reads and writes will unquestionably be more expensive than session
stores and retrieves. If you're running on any reasonable, modern piece of
hardware, with any reasonable, modern web server, you'll have plenty of RAM
available for session storage. Objects stored into the session are kept
within the JVM. Storing and retrieving session objects is a simple matter of
passing a reference to that object back and forth; it's no more expensive
than any other method call with a parameter (well, ok, there's a bit of
additional overhead to retrieve the HttpSession object itself, but that's
still very minor). If you go to a database, you are, at the very least,
incurring the overhead of making that external call. And if the database
ever has to go to disk to retrieve something, it's significantly more
expensive.
At my previous job, I wrote a servlet that stored large amounts of data in
the session (a few objects, but each pretty large). We set a two-hour
timeout for session expiration, so it wasn't unusual for us to have seven
hundred or more sessions hanging around at a time, each with those large
session objects, and we never came close to running out of memory in the
JVM; from the memory standpoint, we could have handled many thousands of
simultaneous sessions.
And just to reiterate what someone else said, remember that session objects
are strictly stored on the server. The cookie that's passed back and forth
to enable sessions is simply a unique identifier so that the server knows
which session is which. (And to answer the question, "What if cookies are
disabled?": the server will try to use URL-rewriting, if possible, to
include the session-id).
--Jim Preston
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of casey kochmer
Sent: Friday, June 16, 2000 9:12 AM
To: [EMAIL PROTECTED]
Subject: Re: Limit on Session variables and Performance
The real answer to your question is:
It all depends on the expected load on your web site. Using session
variables doesn't really effect the perceived speed of your site on small or
average sites. In fact using session variables for the most fequently used
data will help speed up access compared to continued hitting of a database
(unless you cache database results). Where session variables will bite you
is on sites which have a high load factor. If you are storing 100 variables
per person that may not be much data, but storing 100 variables for 1000
people at the same time can begin putting enough load on your web server to
begin effecting performance.
There is no majic number for the ideal number of session variables to use
quite honestly. Just use Session Variables on the extremely reusuable data
and use better judgement and then load test, load test, load test. Session
variables are awesome but don't go overboard.
On average I store only 10 variables per person in the session on my sites.
I also usually stash 5 data arrays or Data objects in my application object.
So when you say 100 variables per session,I suspect you might have some data
that should be stashed in the application object also.
Hope this helps
Casey Kochmer
[EMAIL PROTECTED]
>From: Vaishali Joshi <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
> reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Limit on Session variables and Performance
>Date: Fri, 16 Jun 2000 09:14:44 EDT
>
>Hi All Java gurus
>
>Does anyone has any idea about performance of a site if lots of information
>is stored in a session. There may not be too many sessions at one time, but
>in one session lots of information (around 100 variables) will be stored.
>Some of the information will be too long too as description.
>We are having a tabbed web application, and the issue is whether to store
>the information in a database as we move from one tab to another or should
>we store it in session. Putting it in database will be like lots of calls
>to
>database, and if the user changes the information by going back and forth
>between tabs then we are doing lots of rewriting to the database. And at
>the
>end, user might even cancel everything, so we will end up having these
>kinds
>of useless records in database. But I am not sure about how putting this
>huge number of data in session will affect the performance. The other
>option
>is putting some data in session and some in temp tables..
>
>I would appreciate if you can throw some light on these issues..
>
>Thanks
>Vaishali
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets