Orleans - how to improve reminders precision

Viewed 152

Which the best way to organize Reminders + Timers work?

I want to run a task with precision in a second.

As I understand I need to run a reminder with some interval. And each start of the interval will fire a timer to achieve a specific time. But which interval of reminder should I specify to achieve two goals:

  • Make a very durable solution (mitigate suddenly silo scaledown, silo fault, etc)
  • To Increase the likelihood to achieve needed precision.
  • Minimize timers & reminders overhead
1 Answers

Reminders are for approximate times (minutes), Timers are for precise times. You can create a robust solution by combining the two.

Obviously you will need something that initially creates the grain. You will also need persistent storage for the reminders. Then create a reminder AND a timer in OnActivateAsync().

In the reminder callback check for the existence of the timer, recreate it if necessary.

In the timer callback, make sure you call a grain method

        private async Task SnapshotTimerFired()
        {
            var me = this.AsReference<IScoobyDoGrain>();

            await me.DoSomethingForAScoobySnack();
        }

by making the grain call the runtime will know that grain is alive and try not to deactivate due to memory pressure

Related