I have 2 gateway timer events.
Both of those update all the rooms in our plant.
We decided that the best solution to not block the event is to call invokeAsynchronus function.
So every 5 minutes or so the script executes and generate about 20-30 new threads that update each room.
Our problem is that both events execute at the same time. So every 5 minutes instead of having 20-30 threads we have about 40-60 threads.
Is there any way to offset the events so execute about 2,5 minutes apart?
Thx in advance!
What about using scheduled events instead?
Making threads is a pretty heavy-weight operation. Don't do this. Consider using a 1-minute scheduled event, and based on the modulus of the minute of the hour, execute 20% of the work.
If you really need some parallelism, consider creating a thread pool executor with a fixed pool size, and submitting all of the tasks every 5 minutes.
A (very) simple example. You will need to take into account frequency and offset. :
schedule = [{'script': path.to.script1, 'frequency': 5, 'offset': 0},
{'script': path.to.script2, 'frequency': 5, 'offset': 3}
]
now = system.date.now()
if (now.minutes - item['offset']) % item['frequency'] == 0:
item['script']()