Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a doubt about mysql connction, in my c sharp application I store the user login status in database and i check the status change by using a timer, which ticks in 100 ms delay.The database check function invokes using the timer. Is there any performance problem occurred due to this continues database access to my application?

thanks
Posted

I don't see why you need to do it so frequently. There are probably occasions where network latency and server load would mean the app is trying to update the status before the last update has finished.

Why do you need to record the status at all? [I obviously don't know what you are trying to do, so you may have good cause, just curious that's all).

If anything when the user logs in the first time, record a token in the database, and then only update the status every 10-30 seconds or whatever.

Run this in a background worker thread. Set an expiration time for the token in the database, and then just make sure your application updates this token time before the expiry time. That way if your session/app fails and then then the token will expire, if you app then is restarted and polls for the token, and it is expired, the user must then login again.

You can also then use admin roles to kill tokens etc, forcefully removing sessions from the app. [again, this sort of thing is dependant on what exactly you are trying to achieve and how your multi-user model works]

Bottom line, i would not be trying to poll as frequently as 100ms.
 
Share this answer
 
Yes. If your application is going back a forth to a server 10 times a second to check on something like login status you will definitely incur a performance overhead.

You really shouldn't need to do this?
 
Share this answer
 
database hit on every 100ms is obviously not a good idea.

Is it web application or windows ? Why u want to do such checks ?
 
Share this answer
 
I take it you've got a [users] table and as part of login process you are marking [is_logged_in] to true? Also as part of login you are rejecting any connections where a user attempts to connect with crendentials, but the record retrieved for the user shows them as logged in?


I'd say scrap that logic, doesn't really offer you anything. If a user offers correct combination of user+password, accept they are who they say they are and give them access to the application.

This simplifies things somewhat. You haven't got to worry about this checking for login status etc

You can still mark a user as 'logged in' as part of the login process (can be useful in admin screens to see who is connected, what time they logged in etc) just don't reject based on this flag
 
Share this answer
 
OK there are number of scenarios where u can achieve this requirement and still get better performance.

From your comment i guess its windows application. Well even if its wen application, do allow latest request to log-in on correct credentials. And add some logic to store individual application identifier/token in database. As the recent one gets logged in it will replace previous token with new one and hence on token check all other applications will get logged-out due to mismatch.

For web application you can simply put this token information against username in application variable, this will save lots of database trips. Obviously u can choose different stores to save this info in farming situations.

For windows application, i think its ok if you do such checks on ervey database actions. Try sending requesters context/token to database and do checks there and throw error if it fails.
 
Share this answer
 
Use a separate connection to the database (probably in another thread), and protect your login status in a transaction. When the user logs off, you terminate your transaction, if the whole thing crashes, your TX will be rolled back (possibly after timeout)
 
Share this answer
 
thanks to all
actually I use it to prevent multiple logins. In my application to prevent multiple logins i use a status field in the database, but if the application crash or net work error occurred the user log out status can't be recorded due to this next time user can't login to the application, to resolve this i use a login status reset feature to reset the login status. because of this if i don't continuesly check the status there may possibility of multiple login
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900