File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Tradeoff between backend and front end Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Tradeoff between backend and front end" Watch "Tradeoff between backend and front end" New topic
Author

Tradeoff between backend and front end

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
i am creating an online web examination application. the purpose of the application is that it provides stipulated time for answering each question.I dont want the each user to spend more than the allocated time for each question. here the response time becomes crucial so that next question is automatically fired if the user is unable to answer the question in stipulated time. every test is different for each user.

in order to take care of response time the system generates the entire test from the database at the first requests and loads it to the session. Now for the entire test duration the system just uses this test object loaded to the session instead of firing queries to database for fetching question.I believe accessing data from session object would be faster that creating N number of connections to the database and fetching the data. Is this approach correct ? i am delegating the task of database to the front-end. Is there any other better approach to this. can the sessio get exhausted if there are many users at the same time ? in such a case what are the possible alternatives for making the application scalable with minimum effort?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30955
    
158

Caching in the session is certainly faster than doing a query each time. The best approach depends on how many questions there are in a test, how many questions there are overall and how many users there are.

For example, if there are a lot of questions in a test (or a lot of users) and you are concerned about memory, you could use a "look-ahead" where you only store the next few questions in the session.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
Personally I create tests as XML documents - a test manager keeps track of the DOMs. When the test is loaded, I locate all the Elements defining questions by the question id, but that is all the preprocessing needed. Values for a given question are extracted from the Element on demand. Tests can stay loaded all the time or you could use a least-recently used cache approach.

I have seen all sorts of exam engines which try to use a database - this is silly in my opinion. Memory is cheap, network/database operations expensive.

Compared with all the other memory and cpu consuming processes an in memory DOM is very very efficient.

Sessions should NOT be used for bulky data, just record the current state of the user. I use a serializable test state object which can be stored to disk and recovered if the user connection is lost.

Bill
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
thanks william and jeanne , i think i can reconsider my design options and use a mix of both the approaches told by you. i can use XML as it provides a better in memory storage performance (as told by william)and dom also provides me with a feature of caching a fragment of entire document (fragment of entire document object) (making use of jeanne's design approach)that can be used as per demand. I think this is better than serialising the entire Test.
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
well, the previous answers really sounded helpful, but there is another thing that is coming to my mind since long. my front end is constantly serving various requests. As jeanne suggested that i can always keep a part of the questions in the session and refetch at demand. here we have two different activities that can go independently 1. fetching new questions from the database/XML and setting in the session 2. fetching questions from the session and generating response.

Is it possible and feasible to perform these activities in independent threads. if feasible then i have a better design.

a) during the first request all questions will be fetched from the database and stored as an XML doc.
b) two question (part of document object) will be set to the session. as soon as one question is fired a testbuffermanager will replace the current question with a new one (just like maintaining minimum inventory of questions in the session)
c) I can use Sessionlisteners for capturing changes in the session object. Now why not perform activity a) and b) in different threads.

What do you say ?
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
sorry just a change.

i meant why not perform Question replinishment in session and response generation in different threads.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
a) Fetching all questions at once may cause a delay that will worry your user - I would do some time trials.

Tell us more about your situation:
1. How many simultaneous users?
2. How many unique tests?
3. Composed from how big a database of questions using which criteria?
4. Do you offer a review/learning mode that lets the user review the full graded test?
5. How are questions authored?
6. Just multiple choice questions or more complex?


I have been creating online practice exams since applets with Java 1.02 so I have been over these design problems many many times.

Bill
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Well there will be incremental update in the database, every chapter test will consist of approximately 60 questions. But never more than 60 questions. The number of questions are not exact and the system picks up various types of problems from each topic/subtopic in the chapter. The data base has a collection of 10 unique question for every type of problem in each topic/subtopic. The system would randomly select one question from each type in a topic/subtopic. Every Question is represented as a bean object Question. The Question class encapsulates Response as inner class within it. This ensures one to one correspondence between question fired to the student and response of the student.

What i have done is , my system fires the query to extract all 60 questions (ie. the test paper) and keeps it in the session. Now for the entire duration of test there are no more queries fired to the database not even for response logging. Everything is done in this object (the test paper) that is stored in the session.

we obtain a, reference to the testpaper object, in the session and use its itorator to fetch a new question that is sent to the student.
The student responds the question - this response is saved as Question.Response object for the Current Question (As i said earlier every Question object will have an enclosed Response object that will store student response details). after the test is over. this entire Testpaper object is used for evaluating the final report. and an insert query is fired that logs the result to the database.

we can expect approximately 600 students at a time for whom this system will be tested initially (live test scenario in a college). Then we will try to scale it upto 3500.

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
although now i am considering restructuring of the design based on what we discussed in the previous conversation i.e. use of XML for storing the TestPaper and using DOM for fetching questions from XML to maintain an inventory of not more than 2 to 3 questions in the session. This way there will be less load on the heap as well as on the database.

But i dont know anything about how to performance tune the system to match performance requirements. what should i do ? is there any way to calculate the performance like Time of processing response, Memory allocated at runtime, load on the database.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
Storing entire test question sets for hundreds of students in sessions may seriously strain the session mechanism. The server will be serializing sessions to disk to save memory. I would certainly do time trials.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tradeoff between backend and front end