The answer is different in different cases:

- javax.servlet.http.HttpSession:

  things you put into the Session should be serializable because, in a multi-server 
situation, the server farm might find it prudent to zap your user's session across to 
a less busy server.

  ( I don't know of any Servlet Engines that does this ... I would be interested to 
know which ones do ).


- EJB session beans:

  members of the SessionBean you want to always be there should be serializable 
becuase at the discretion of the EJB server, which is managing resources, your 
SessionBean might be written to disk in-between calls from a client, and then read 
from disk later on.


In both cases, the issue of resource use is significant - you don't want your user 
sessions lasting too long and holding too much - the number of users you can handle 
will decrease as resource usage increases.  If there are not enough resources for the 
given user load, then Serialization will begin to occur, which has the same effect as 
RAM<-->disk swapping in your favourite bloatware, on overall performance.


So you have to balance up the size of the object, with the costs of storing and 
retrieving it, or reconnecting, or whatever it takes to re-create it.  Some people 
believe that using 'stateful' user-sessions like this is too much of a performance 
risk, but it depends on what you expect to get from your hardware.

The strategies open to you include:
1. put the state into the HTML page that the user's browser has, and then use that 
information when processing the request.
2. put the state in the HttpSession.
3. put the state in a stateful EJB SessionBean ( designed for such a purpose ).

There is no doubting that #3, using a stateful SessionBean is the *easiest*, but be 
aware that some clustering architectures don't handle SessionBeans very well ( check 
your particular EJB vendor for their recommendation if scalability is important to you 
).  ... note: if your application is going to be 'public' to the 'net, then 
scalability is *very* important to you.

In terms of scalability, it is almost universally agreed that 'stateful services' with 
'idempotent' methods is the most *scalable* approach.  ( note that this does not 
necessarily mean 'best performing per ounce of hardware' - it simply means it is easy 
to cluster ).  In this case, use #1 with Stateless session beans.


Even with using either #1 or #3, you will find that for some modes of operation it is 
useful to have an HttpSession with some information ( eg. a reference to the EJB 
server, and their user credentials ) stored at that level.



In short, there are no universal answers - it will alwasy depend on the nature of your 
application.

However, I hope these guiding principles help.


regards,
David.




On Thu, 22 Feb 2001, Whaley, Dave (HQP) wrote:

> I found the servlet-interest archives and found a trail of discussion on the
> topic. Sorry if this question is old news.
>
> The consensus is that the JVM stores the session data in general RAM.
> Therefore, there is no real technological limitation of storing objects in
> the session.
>
> However, I sense there is more to the story. For example, under certain
> conditions the session objects may have to be serialized. One archive
> message said that it is the serialization itself that causes a lot of
> overhead processing. The serialization seems to happen either when multiple
> web servers are used, or for RMI calls. The EJB spec says to make session
> objects serializable.
>
> I would still like to hear your comments.
>
> . . . . . . . . . . . . . . . .
> Dave Whaley
> Developer, Web Applications
> Robert Half International, Inc.
> [EMAIL PROTECTED]
> . . . . . . . . . . . . . . . .
>


David Bullock
LISAsoft Project Lead
Sun Certified Programmer for the Java 2 Platform

 email: [EMAIL PROTECTED]
mobile: +61 4 0290 1228

"The key ingredients of success are a crystal-clear goal,
a realistic attack plan to achieve that goal,
and consistent, daily action to reach that goal."

Steve Maguire, "Debugging the Development Process".

LISAsoft
http://www.lisasoft.com/

Adelaide                  Sydney
--------------------      ------------------------
38 Greenhill Rd           Level 3, 228 Pitt Street
Wayville S.A. 5034        Sydney NSW 2000
Australia                 Australia

PH  +61 8 8272 1555       PH  +61 2 9283 0877
FAX +61 8 8271 1199       FAX +61 2 9283 0866
--------------------      ------------------------

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to