Alan is correct that the Servlet API does not expose a direct way (for
a servlet developer) to obtain a reference to all sessions created
within a context (i.e. webapp).

It would be possible to write a servlet Listener that shoves a
reference to all sessions into some app-wide structure (a Map for
example), but hanging onto session objects can quickly present
challenges with regard to out of memory, etc... depending on how much
data is being stored, the request load, the lifespan of each session,
etc...
The code hanging onto the sessions would need to be fairly robust,
evicting expired ones on some schedule.
For this reason I would not recommend it.

Most Servlet/JSP Engines already have complicated session management
code built-in for this, but exposing the sort of data you're wanting
is not part of the Servlet specification.

The Admin UI for New Atlanta's ServletExec provides some of this info
on a per-webapp basis (# of active sessions, max # of sessions, the
types and # of the attribute values stored within each given session,
lifespan of each session, last time a given session was accessed). SE
also offers pluggable session management so that a person could write
their own session manager (perhaps one that tracks the amount of RAM
used by each session)  but I don't know of any other Servlet/JSP
Engines that offers that feature so it would not be a solution for all
brands of servlet/JSP engine.

Computing how much RAM a given session (and the attributes stored
within it) is currently using is a potentially expensive operation
depending on what's in each session and how many their are.
Serializing the entire session object to a byte array and then
reporting the length of that array would be one rough (and potentially
expensive) way to get a ballpark number for that.

Matt



On Tue, Jan 5, 2010 at 11:04 AM, Alan Williamson <[email protected]> wrote:
> This is indeed an interesting idea.
>
> I recently had the need to iterate through all the application's that
> were defined, so maybe this could be hooked into that functionality.
>
> Although, from memory, i __don't__ think the Servlet API lets us iterate
> through all the sessions, so i don't think we can get at that
> information in a uniform manner.
>
> Hugo Ahlenius wrote:
>> | Define "information about those sessions" and we'll see what we can do.
>> | Always helps to hear what people want to see in the admin console, so
>> | thanks!
>>
>> For starters sessions per application, but maybe also explore each session
>> in more detail (if there are not too many? - then I guess one could also
>> have max/min/average- both current and for the lifetime of the openbd
>> instance).
>>
>> Details could be:
>> * memory consumption per session
>> * lifetime of sessions (when they started)
>> * ip's
>> * ?
>>
>> Wouldn't that be something?
>
>
> --
> aw2.0
>   http://www.aw20.co.uk/
>
> --
> Open BlueDragon Public Mailing List
>  http://www.openbluedragon.org/   http://twitter.com/OpenBlueDragon
>  mailing list - http://groups.google.com/group/openbd?hl=en
>
>  !! save a network - please trim replies before posting !!
-- 
Open BlueDragon Public Mailing List
 http://www.openbluedragon.org/   http://twitter.com/OpenBlueDragon
 mailing list - http://groups.google.com/group/openbd?hl=en

 !! save a network - please trim replies before posting !!

Reply via email to