wood burning stoves 2.0*
The moose likes Performance and the fly likes Threads/pooled sessions and cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Threads/pooled sessions and cache" Watch "Threads/pooled sessions and cache" New topic
Author

Threads/pooled sessions and cache

Amer Seifeddine
Ranch Hand

Joined: Apr 25, 2002
Posts: 57
Hello there,
I am trying to design an application and I want to hear the expert advice.. Here is the senario:
users (jsp threads) are going to hit my application and there is a pool of sessions ready for them. Every thread (jsp) is going to get a session from the business application (from the pool). Questions:

1-How can I associate a jsp thread with the session pool in order to get one? Will a queue and monitor is the best way (then how to queue a jsp thread on the business app)? Or just leave every jsp thread to get a session on his own?

2-What is better from performance point of view: having server static storage (Map) for caching dictionaries or having instances of (Map)s on the server side (singleton server instance) as variables?

Thanks!
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
The dispatcher should be a static method, returning an instance of a runnable or thread object. ( Henry, correct my nomenclature here ) The dispatcher should be based on either a Map or a Queue. See   JSP Declarations   - there are some pitfalls waiting. Doing threads from jsp is challenging.

I suggest setting up a static Map but that is my personal design pref, the circular list model is as well candidate but check out ThreadPool to see if it has a .nextAvailable()

There are two issues here. Dispatching the runnables or threads - in general a thread is not re-runnable except by system designed dispatchers but a runnable is. The ( collision ? ) of two ( or more ) threads on a single runnable ( it's variables more correctly ) brings hairy issues if we try to do it from jsp.

I would set up a server static storage (Map) for caching dictionaries in the init() method of a servlet. There should be known ways of calling a servlet from a jsp - you could then use the jsp to assign a session id before passing the request to the servlet, which manages the session pool in the servlet - the servlet doing all interfacing to the business app.

Servlets have an init() method, I do not think there is one for jsp. JSP does however have an effective approach for managing the request object.

What to do if the server becomes loaded is also a significant design issue.
[ May 01, 2008: Message edited by: Nicholas Jordan ]

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Amer Seifeddine
Ranch Hand

Joined: Apr 25, 2002
Posts: 57
Well, the thing here is that the application is totaly independant of the jsp server. The business application's session can be taken either by rmi ( if remote jsp server) or locally ( same jvm) by returning the session directly instead of looking ip up.

From performance point of view, would a static map or instance map ( map variable of the single instance of main server class) be the best?

Also, server (again independant) has already a design of monitor/threads and Queue model and sessions are pooled and ready for users to get.. From performance point of view, shall i queue threads coming from the jsp server and serve them sessions based on the model described above or just let jsp threads get new sessions and i give up with pooling them?

thanks again
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Okay, this cleans up the design greatly. How does the business application's session key it's session? More correctly, can you get a unique session identifier from the business app. What is meant by "can be taken" ? Remote / local may be dismissed as a major design issue if the business app is cleanly separate and addressable from a java app.

Performance point of view would prefer a static map for the lookup, but the lookup has to be synchronized. It can be that individual dictionaries are possible and should be considered as candidates in design and testing, but it is the Threading issue that is of consequence moreso than static v instance. The design pattern is well known, I have been looking at it doing security issue studies and it is used all over the security package so it must be a proven design paradigm.

The way the static dictionary achieves performance reliability is that the entire design does not spend too much time in look-up, and java.util has several classes that are proven for fast lookup. You should normally have a very short wait time for dictionary objects, it is the synchronization ( in many places ) that could render the design ineffective.

What does the jsp server has as an anticipated traffic load?
Amer Seifeddine
Ranch Hand

Joined: Apr 25, 2002
Posts: 57
Thanks for the reply. yes, it is possible to return a unique id ( static variable on the app server synchronized and being inceremented with every request)..

The reason of seperating the business app is that it can be used with web services/visual basic (java objects in VB)/ejb etc.. any external business accesses it by either getting Local session or looking up a service which provides a remote reference of the same session..

Now, I agree that the threading issue is more important and I am going to use static objects for storage.. i am aware of tuning maps/records and that part was also designed for fastest access using new concepts. Access will be sycchronized only if they are subject to a modification.. am I RIGHT?

and what is your opinion about pooling sessions and queuing incoming jsp threads?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Okay, design is challenge is simplifiying. How do we determine a unique session id for incoming sessions if it is a customer ( or request or however your incoming traffic is styled ) if we have not seen that customer before? Is the customer base ( however styled ) something that comes in with no prior introduction - thus requiring an original generation of a customer id or are all potential requestors from known sources with id's that can be assigned prior to first request.

The reason of seperating the business app is that it can be used with web services/visual basic (java objects in VB)/ejb etc.. any external business accesses it by either getting Local session or looking up a service which provides a remote reference of the same session..


Good design, probably would be approved by the OO camp, but as well works well with my concept of how the machine and application work as a unit.

...and what is your opinion about pooling sessions and queuing incoming jsp threads?


My opinion is that we need to work that slice of the design in the Threads and Synchronization forum, which I have already worked your post there for that segment of the design. For the moment inspect the java.util.Collection(s) and java.util.concurrent packages.

See:



[ May 01, 2008: Message edited by: Nicholas Jordan ]
Amer Seifeddine
Ranch Hand

Joined: Apr 25, 2002
Posts: 57
Sessions will be locked after setting the sessioninfo built by the client. sessioninfo contains the server uniqueid which is generated after successful login.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
So what we are trying to do here is manage session id with the jsp?

It can be done but consider servlets, the servelet can juggle a static map with a static synchronized accessor method - that will run just fine from a jsp and it can pass the request off to the business server with the login built by the servlet.

I have not figured out how we call a servlet from a jsp, that is what I am working on right now in my primary app. It has been almost a month since I was coding it, I delved into java.security issues. I suggest ( at moderator's discrestion ) posting in one of several fora listed on the saloon.java page:



Probably should give those fora a visit before continuing.
[ May 01, 2008: Message edited by: Nicholas Jordan ]
Amer Seifeddine
Ranch Hand

Joined: Apr 25, 2002
Posts: 57
I appreciate your replies.. Just to clarify,.. the link between jsp area and business area is that the jsp (http) session stores this remote session reference ( or local!). the remote business session id is not the same as jsp session id..

** jsp creates a sessioninfo on client side, lookup the firewall and tries to authenticate. if that is ok, the sessioninfo gets a server sessionid by firewall ( busniess jvm) and then passed to the serversession as parameter (serversession.setInfo(sessioninfo)) and serversession is locked for that request/released by pool if user is inactive for some time and all user objects are set to null. This helps tracking user's objects to be gc..

Now. since the http session is bound to the serversession (rmi remote or actual local object) user are always known for the business by the server session...

the part i am working now is to queue jsp requests to get one server session by the firewall.. After authentication, we need a server session:
1- Queue the request
2- Monitor checks it
3- available business app thread processes the request and assigns the available non-locked session..
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
the link between jsp area and business area is that the jsp (http) session stores this remote session reference ( or local!). the remote business session id is not the same as jsp session id..


Stack these up or Map them or any java.util.Collections class that makes sense to you - give selection of which class or interface careful consideration and reconsideration. Subject the selection to testing. Acess by static synchronized acessor method.

jsp creates a sessioninfo on client side, lookup the firewall and tries to authenticate. if that is ok, the sessioninfo gets a server sessionid by firewall ( busniess jvm) and then passed to the serversession as parameter (serversession.setInfo(sessioninfo)) and serversession is locked for that request/released by pool if user is inactive for some time and all user objects are set to null.


Consider posting your design challenge in the jsp forum.

This helps tracking user's objects to be gc..


Only ten engineers in the entire world know how and when to call the gc correctly. They all work under the Sun and probably let jvm do the gc call when it decides.

Now. since the http session is bound to the serversession (rmi remote or actual local object) user are always known for the business by the server session...


This has probably been developed already somewhere - in Java.

2- Monitor checks it


Describe how the monitor works, may be needful to consider the monitor in the Security forum at JR-Saloon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads/pooled sessions and cache
 
Similar Threads
using tread.sleep in MDB
Struts 2 session writing efficiency / timing
Synchronous & Asynchronous framework
multithreaded web application session issue
please answer this 128 questions for WLS. Urgently!