Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 487
Jitendra Pancholi Avatar asked Nov 09 '22 16:11

Jitendra Pancholi


1 Answers

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.

like image 86
Rolwin Crasta Avatar answered Nov 14 '22 23:11

Rolwin Crasta