Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Two performance Questions  RSS feed

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I am creating an online examination system. Here several users will be able to give the test simultaneously.Because it is a time sensitive application i am generating the entire Test specific to every student and putting it in the Session context. rest all the requests will be served by this Test object that will keep providing the next question. If i had not used this approach i would have to query the database for every question. Have i used the correct approach? Are there any other approaches possible.

2. In my database i have three related tables, i need to access data from all the three related tables namely Subject_Master, Question_Master, Chapter_Master. since the test generated will have mixed questions from three subject therefore resultset would include subject code, chapter Code, question code. Because every chapter can have several question my resultset would look something like this



QID------QDESC-----CHID----SID
____________________________
1 ---------abc---------NWL-----PHY
2 ---------def---------CGM------MTH
3 ---------sdf ---------CGM-----MTH
4 ---------jkl ---------OPT------PHY
5 ---------tyu ---------THC------CHM
6 ---------fgd---------CGM------MTH
7 ---------fwr----------NWL------PHY
8 ----------ghi----------THC------CHM
.
.
_____________________________

PHY - Physics, CHM - Chemistry, MTH - Math



here we can see that i am getting multiple results for the questions from each chapter although i need a single question from every chapter in any subject. Here i could have fired a seperate query for finding a single question randomly from every chapter in the database and then adding that question to the Test. But i prefer to fire a single Query to find all the question from all the chapters from the subjects and then filter this resultset to select randomly a questions from each chepter to add it to the Test. In simple words what i am doing is instead of firing several Queries and doing the random selection in the database i am designating this task in the application. I feel we must refrain from puuting too much responsibility to the database if it can be done through the application. Is my approach correct ? what are the other possible solutions ?
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many aspects when you are talking about web applications' performance tuning/scalability. Just to name a few - type of server, app server clustering, load balancer between client and middle ware, database clustering, etc.

for a simple environment, I would have created an object with just a handful questions pulled in advance rather than all at once. It is very important to keep memory in control and at the same time, high [time-based] performance.

I could not clearly follow your second query about database. Can you post the SQL which you are using and kind of pseudo code so that it would be easier to understand for the reader?
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shukla raghav wrote:1. I am creating an online examination system. Here several users will be able to give the test simultaneously.Because it is a time sensitive application i am generating the entire Test specific to every student and putting it in the Session context. rest all the requests will be served by this Test object that will keep providing the next question. If i had not used this approach i would have to query the database for every question. Have i used the correct approach? Are there any other approaches possible.

2. In my database i have three related tables, i need to access data from all the three related tables namely Subject_Master, Question_Master, Chapter_Master. since the test generated will have mixed questions from three subject therefore resultset would include subject code, chapter Code, question code. Because every chapter can have several question my resultset would look something like this



QID------QDESC-----CHID----SID
____________________________
1 ---------abc---------NWL-----PHY
2 ---------def---------CGM------MTH
3 ---------sdf ---------CGM-----MTH
4 ---------jkl ---------OPT------PHY
5 ---------tyu ---------THC------CHM
6 ---------fgd---------CGM------MTH
7 ---------fwr----------NWL------PHY
8 ----------ghi----------THC------CHM
.
.
_____________________________

PHY - Physics, CHM - Chemistry, MTH - Math



here we can see that i am getting multiple results for the questions from each chapter although i need a single question from every chapter in any subject. Here i could have fired a seperate query for finding a single question randomly from every chapter in the database and then adding that question to the Test. But i prefer to fire a single Query to find all the question from all the chapters from the subjects and then filter this resultset to select randomly a questions from each chepter to add it to the Test. In simple words what i am doing is instead of firing several Queries and doing the random selection in the database i am designating this task in the application. I feel we must refrain from puuting too much responsibility to the database if it can be done through the application. Is my approach correct ? what are the other possible solutions ?


You're optimizing prematurely. Your assumption that querying each question on demand being a significant performance issue is probably not based on performance testing. Most if not all well known relational database use various techniques to optimize repeated queries (result set caching for example). You're probably looking at query times that are well below 1ms after a few repeated queries so unless many thousands use your app concurrently there wont be much of a performance issue. And when you have numbers beyond that you should probably still prefer the database route since keeping the entire test in memory for each of those 1000+ users is likely to give you memory problems. And remember, you can always batch query, say, a 100 questions, let your students "consume" them and query a new batch when the pool is empty. That way you'll still avoid frequent database queries without running into memory issues.

Again, test query performance and only optimize if that performance is lacking. When that is the case first look at query optimalization. After that I'd look at batching (i.e. query 100 for each CHID-SID combination for example, and let your sessions consume them, then refill the empty pools on demand). As I've mentioned saving all questions for all tests in a session object will eventually become a memory problem.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!