473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Session storage vs. frequent DB calls

Hi,

I'm developing web surveys where users logon to a web survey and answer up
to about 50 questions, one after the other, shown only one question at a
time. The answers are saved in a database.

A fellow developer and I are discussing when is the best time to save the
answers. We have two approaches in mind:

Approach 1:
After each question is answered, the answer is saved in the database.
Sessions are only used to store the User ID.

Approach 2:
After each question is answered, the answer is saved in a session variable.
When the user has finished the entire survey, all the answers are saved at
once in the database. Also, if the user logs out, or if the session times
out, the answers answered so far are all saved in the database at once.

The amount of actual data sent to the database is the same in both
approaches, but Approach 1 have much more frequent calls to the DB, thus
creating an overhead of opening and closing connections. I'm not sure how
significant that is. On the oter hand, Approach 2 store a lot of data in
sessions. I'm not sure how bad a thing that is.

Which approach is better and for what reasons? I'd be happy to supply more
information if needed.

If this question is better asked in a different newsgroup, please let me
know.

Best regards,
Rune
Jul 19 '05 #1
8 1681
CJM
My answer would be that it doesnt matter.

The overhead for multiple DB calls is negligible, especially when connection
pooling is utilised. The overhead for storing so little information in a
Session variable is negligible, unless you have an VERY large number of
concurrent users.

You could avoid both if you really wanted to: pass the concatenated answers
to the next page (encrypted, of course) in a querystring. Store the
concatenated answers in a hidden form field, and POST to each page... I'm
sure there are many other weird & wonderful ways of doing it, but does it
really matter?

So I would concentrate on functionality. Do you want to abandon a survey if
not completed or do you want to salvage what you can? If you want to keep
the data from an unfinished survey, you can use the DB route or you could
store the answers in a cookie. If you want to abandon unfinished surveys,
then it doesnt matter what you do.

hth

Chris

"Rune" <rune[insert current year]@runevision.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm developing web surveys where users logon to a web survey and answer up
to about 50 questions, one after the other, shown only one question at a
time. The answers are saved in a database.

A fellow developer and I are discussing when is the best time to save the
answers. We have two approaches in mind:

Approach 1:
After each question is answered, the answer is saved in the database.
Sessions are only used to store the User ID.

Approach 2:
After each question is answered, the answer is saved in a session variable. When the user has finished the entire survey, all the answers are saved at
once in the database. Also, if the user logs out, or if the session times
out, the answers answered so far are all saved in the database at once.

The amount of actual data sent to the database is the same in both
approaches, but Approach 1 have much more frequent calls to the DB, thus
creating an overhead of opening and closing connections. I'm not sure how
significant that is. On the oter hand, Approach 2 store a lot of data in
sessions. I'm not sure how bad a thing that is.

Which approach is better and for what reasons? I'd be happy to supply more
information if needed.

If this question is better asked in a different newsgroup, please let me
know.

Best regards,
Rune

Jul 19 '05 #2
CJM wrote:
My answer would be that it doesnt matter.

The overhead for multiple DB calls is negligible, especially when
connection pooling is utilised. The overhead for storing so little
information in a Session variable is negligible, unless you have an
VERY large number of concurrent users.
Some of out previous surveys (using multiple DB calls) slowed down the
server a lot when many users were connected at the same time, so it seems to
matter.
You could avoid both if you really wanted to: pass the concatenated
answers to the next page (encrypted, of course) in a querystring.
The querystring can only hold 1024 characters in total, which in this case
is not enough.
Store the concatenated answers in a hidden form field, and POST to
each page...
This would mean transfering the same data back and forth between server and
client again and again. This seems very ineffecient.
I'm sure there are many other weird & wonderful ways of
doing it, but does it really matter?
Yes, I would say so. See above.
So I would concentrate on functionality. Do you want to abandon a
survey if not completed or do you want to salvage what you can?
The idea is that the user can log off and return later and finish the rest
of the survey. Thus we save data from unfinished surveys.
If
you want to keep the data from an unfinished survey, you can use the
DB route or you could store the answers in a cookie.


We use session cookies to be able to use sessions, but we don't want to
force the user to turn on cookies for long term storage of information.
Apparently many people use high security and privacy settings.

Rune
Jul 19 '05 #3
> We use session cookies to be able to use sessions, but we don't want to
force the user to turn on cookies for long term storage of information.


So store it in a database and make them log in to retrieve half-finished
forms.

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #4
CJM

"Rune" <rune[insert current year]@runevision.com> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
CJM wrote:
My answer would be that it doesnt matter.

The overhead for multiple DB calls is negligible, especially when
connection pooling is utilised. The overhead for storing so little
information in a Session variable is negligible, unless you have an
VERY large number of concurrent users.
Some of out previous surveys (using multiple DB calls) slowed down the
server a lot when many users were connected at the same time, so it seems

to matter.

What database are you using? I'm not sure what kind of numbers you are
talking about but unless you really do have LOTS of concurrent users you
shouldnt have too many problems.
You could avoid both if you really wanted to: pass the concatenated
answers to the next page (encrypted, of course) in a querystring.


The querystring can only hold 1024 characters in total, which in this case
is not enough.


To be honest, I kind of made an assumption that it was a multiple choice
survey, in which case 1024 should be plenty.
Store the concatenated answers in a hidden form field, and POST to
each page...
This would mean transfering the same data back and forth between server

and client again and again. This seems very ineffecient.

It is, I guess. but it lowers the load on your DB, if that indeed is the
bottleneck.
So I would concentrate on functionality. Do you want to abandon a
survey if not completed or do you want to salvage what you can?


The idea is that the user can log off and return later and finish the rest
of the survey. Thus we save data from unfinished surveys.


Fair enough... in which case, the DB solution seems the best solution,
doesnt it?

Obviously, only you know how much data and of what type it is... but it
seems clear from what you have said that the Db route is indeed the most
sensible route.

If you are using and industrial strength DB, e.g. SQL Server/MySQL etc, then
you shouldnt have too much of a problem. If you are, it might be worth
posting some code examples to see if we can streamlines your code a
little...

Chris
Jul 19 '05 #5
Actually, and I feel slightly stupid saying this, the surveys so far have
been running on an Access database (which explains the slow-down), while the
future planned surveys will probably run on mySQL - not Access anyway.

The thing is, while I have been an advocate of the frequent DB calls
approach (mainly due to convenience and ease of implementation), my fellow
developer was suggesting the "store in sessions, save all data in DB at the
end" approach, due to the lower frequency of DB calls. - Hearing you guys
say that the DB calls overhead really is neglible (when run on a proper
database) is very nice actually. :)

Thanks for the feedback.

Rune
Jul 19 '05 #6
One problem with the session-based approach is that you will not be able to
save the data on session-timeout as you mentioned earlier. I believe that
when the session_onend routine in global.asa is called the session data is
already gone.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Rune" <rune[insert current year]@runevision.com> wrote in message
news:Ox*************@TK2MSFTNGP12.phx.gbl...
Actually, and I feel slightly stupid saying this, the surveys so far have
been running on an Access database (which explains the slow-down), while the future planned surveys will probably run on mySQL - not Access anyway.

The thing is, while I have been an advocate of the frequent DB calls
approach (mainly due to convenience and ease of implementation), my fellow
developer was suggesting the "store in sessions, save all data in DB at the end" approach, due to the lower frequency of DB calls. - Hearing you guys
say that the DB calls overhead really is neglible (when run on a proper
database) is very nice actually. :)

Thanks for the feedback.

Rune

Jul 19 '05 #7
CJM
Plus you can rely on Session_OnEnd actually firing...

"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
One problem with the session-based approach is that you will not be able to save the data on session-timeout as you mentioned earlier. I believe that
when the session_onend routine in global.asa is called the session data is
already gone.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

Jul 19 '05 #8
CJM
Er...that was supposed to be a *can't*
"CJM" <cj*******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Plus you can rely on Session_OnEnd actually firing...

Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Vic Spainhower | last post by:
Hello, I just purchased a new domain name and I've set it up as a redirect to a folder on my main site. What is happening is the index.php page checks a session variable to see if the user is...
0
by: Thotatri | last post by:
hi, I am facing a session time out problem once after installing .net framework 1.1 . The problem is session is getting expired on frequently say 5 mts like that.I have good configuration &...
2
by: adam | last post by:
Having spent nearly 2 years in win forms land the inevitable request came for me to "do some web pages". So being new to this bit of .net and having had a look around I can't see where the best...
8
by: Anthony P. Mancini | last post by:
I'm working on a proof of concept that will ultimately be deployed on a load balancer. For the sake of a preliminary demonstration I created a C# object and marked it's attributes as Public...
4
by: Ralph Krausse | last post by:
ViewState = "Bill"; -- This statement will send that to the browser and hash it into the __VIEWSTATE hidden varible Application = "Bill"; -- This statement will keep this info on the server ...
2
by: Markus Prediger | last post by:
Hi NG, I have an asp.net project that uses an vb6 com object for some database-manipulation (I cannot rewrite it in .net, sorry, its not my decision). I want it to be instanciated seperately...
4
by: Sarah Marriott | last post by:
Our website contains session variables that are used to validate if a user is logged in etc. We have found that these variables are randomly lost while navigating the website. We set up some...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
4
by: j.wendelmuth | last post by:
Hi, i have a problem with PHP sessions. The problem only occurs on one machine (PHP v5.2.4 incl. mod_security). On another one (PHP v5.2.0 no mod security) my application works fine. Here's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.