even out ressource usage for scheduled backups, add random time offsets
The problem
Currently scheduled backups always start at the full hour. With more than a few clients in a network, this can lead to network / ressource congestion.
Requested Solution
It would be nice to be able to stagger the runs in a way that evens out the ressource usage in an environment with more than a few clients without too much planning. The easiest way to implement is probably to give a client a time window in which randomly to start the backup process. Something like "may start between -30min and 30min".
Alternatives
Building a more sophisticated solution is probably absolutely possible. Clients might measure their average backup time and use the median to select their own offset windows, clients might coordinate via avahi or something to limit the number of concurrent running instances on a flat network. I think, a random offset would be the easiest to implement though and should fix most pain easily.
Additional context
My actual problem is, that I have around 10-ish desktops running on a network with a 40MBit/s uplink. The scheduled backups always produce a peak in bandwidth usage around the full hour mark which would be nicer if it were evened out. I assume the same happens to people regarding their storage on the local LAN with a higher number of clients.
Sure about this? I thought we use the time of the last backup +1h or something?
Well, yes, I'm relatively certain. If I use the "periodical" setting in this dialog, the backup always starts at whatever-target-hour and 0 minutes. The archives in the machines which I use that at are dated for 0 minutes to the full hour and the bandwidth peaks on the uplink occur at 0 minutes to the full hour. That's why I brought up this idea. If I'm on the wrong road here, please to correct me though.
If I understand it correctly, the next execution time for a reular interval is calculated here: https://github.com/borgbase/vorta/blob/master/src/vorta/scheduler.py#L308
Let's step through that with an assumed "now" and "last_time" of "10:14".
Step 1: Calculate delta:
delta = dt.now() - last_time
In this case, delta would be:
delta = 10:14 − 10:14 = 0 minutes
Step 2: Calculate the remainder of delta divided by the interval:
delta % timedelta(hours=1)
0 minutes mod 1 hour = 0 minutes
Step 3: Subtract the remainder from the current time:
next_time = dt.now() - delta % timedelta(hours=1)
next_time = 10:14 − 0 minutes = 10:14
Step 4: Add the interval to next_time:
next_time += timedelta(hours=1)
next_time = 10:14 + 1 hour = 11:14
Hm. Looks like you're right @m3nu . This should execute at any minute. Let me check my end and what might be the issue here.
Yeah, forget it. There apparently has been some major redesigning around the scheduling of periodical tasks for 0.8.4.
And now guess what I've been using without giving much thought:
Sorry. I'll see to it that I fix that, looking at the current scheduling logic this should work then. Issue can be closed.