Jitendra Pancholi
Jitendra Pancholi

Reputation: 7552

Optimize the application with huge number of database requests per minute

I have to provide free demo of some service to end users in my application. Free demo could be of 30 mins, 1 hours, 5 hours etc. (predefined time) for a new user for one time only.

User can also consume that time in parts. like in 30 mins of free demo, they can use like 10 mins today, 15 mins tomorrow and rest of the time on next day etc. Now If a user opt the free demo of 30 mins and logged in & using the service. I can restrict the user for 30 mins via his start time & end time. I can send them to payment page if sum of start & end-time is equals to 30 min.

Now problem arises with some uncertain conditions like what if user closes the browser or their internet stopped working or anything else at their end during their active session. In this, I can't calculate their consumed time because of lack of endtime.

Scenario could be like below (for 30 min demo).

UserID  StartTime           EndTime             Consumed(mins)
10      09-04-2015 10:00    09-04-2015 10:10        10
10      10-04-2015 05:00    10-04-2015 05:04        4
10      11-04-2015 07:46    11-04-2015 07:56        10
10      11-04-2015 10:00    // Browser closed or any uncertain condition
10      11-04-2015 11:00    // How to restrict user to use actual 30 mins because I do not have EndTime in above row to calculate Consumed mins.

I may have more than 100000 users at the time same to use our services, So I am finding an efficient solution for this.

As per my understanding, I can create a Separate Job to check user's LastActiviteTime and based on that I can update their Consumed(mins) in database. That Job would be executed every minute and also on the other hand, browser of each session user would update the LastActiveTime in database.

This can solve my problem but I'm not very sure about the performance of my application because of huge number of database request per minute.

Upvotes: 5

Views: 231

Answers (3)

Guanxi
Guanxi

Reputation: 3131

If user is interacting with your service, use these interaction instances as last used time, and if there is need to identify time when you don't have end time, use last interaction time as time to identify end of a session.

simplest would be adding one more column to the table you have showed as lastInteractionTime. And if there is no end time use that lastInteractionTime to calculate consumed time.

Upvotes: 0

Plamen G
Plamen G

Reputation: 4759

I'd suggest conducting a performance test to assess the impact on the database with a bit more than the maximum load expected. Then, depending on the outcome, you might consider using a NoSQL solution like RavenDB to persist usage data. NoSQL could work wonders and is a great match for such problems.

Of course, you can do this with scheduled client-side script and AJAX as Rolwin C already suggested. Just keep in mind that even though there are some obstacles in the way of malicious users, there is always a level of risk taken with this approach. So see if this risk is acceptable in your case as it can greatly decrease the burden on the database server.

Upvotes: 0

Rolwin Crasta
Rolwin Crasta

Reputation: 4339

You could probably also do the Start, End time validation trough client script with JavaScript and store the Start time, end time in browser cookie and run an timely script (java script that executes every minute), so if the validation fails on the client side itself you don't need to validate it on the server(database) side, this way a lot of user queries to the db will be cut down.

Upvotes: 1

Related Questions