I'm trying to write a new API that can support many devices. There will be at least 50k devices in the beginning that will connect to the server using an HTTP API on a daily basis to receive updates.
The number of devices increases with time (with new installations).
The devices need to contact the server once per day to get information.
The time for making this call doesn't matter.
I want to ensure that the request calls from devices are randomly distributed so as to balance the load on the server.
Suppose that in response to the API call, I have information regarding the next request datetime.
What is a good way to find the optimal time for making this call (within next 24 hrs)? Once suggested, all devices should continue calling at that given time every day.
As this will be a global solution, I plan to pick a time much later after regular working hours for the given device. Let's say 10 PM to 5 AM is the suggested time for each region.
Within those 7 hours, how can I evenly distribute the time for any given device?
Some additional info:
- Time will be allocated for the device when it is making a valid request for the first time
- You can manually force the device to make the call using client software, but that does not change the default settings. But it will also be possible to change the time from the server manually (force entry- no logic required).
I have devised a crude way of tracking the log per minute [minuteofday], [frequency], by selecting the one with the lowest frequency. This should log with respect to a constant of 1440 entries. There is always a chance for race situations.
I also need to assign additional resource when needed.