internal LocalReminderService( SiloAddress addr, GrainId id, IConsistentRingProvider ring, OrleansTaskScheduler localScheduler, IReminderTable reminderTable, GlobalConfiguration config, TimeSpan initTimeout) : base(id, addr) { logger = TraceLogger.GetLogger("ReminderService", TraceLogger.LoggerType.Runtime); localReminders = new Dictionary <ReminderIdentity, LocalReminderData>(); this.ring = ring; scheduler = localScheduler; this.reminderTable = reminderTable; this.config = config; this.initTimeout = initTimeout; status = ReminderServiceStatus.Booting; myRange = null; localTableSequence = 0; tardinessStat = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.REMINDERS_AVERAGE_TARDINESS_SECONDS); IntValueStatistic.FindOrCreate(StatisticNames.REMINDERS_NUMBER_ACTIVE_REMINDERS, () => localReminders.Count); ticksDeliveredStat = CounterStatistic.FindOrCreate(StatisticNames.REMINDERS_COUNTERS_TICKS_DELIVERED); startedTask = new TaskCompletionSource <bool>(); }
internal static void Init() { StorageReadTotal = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_READ_TOTAL); StorageWriteTotal = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_WRITE_TOTAL); StorageActivateTotal = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_ACTIVATE_TOTAL); StorageReadErrors = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_READ_ERRORS); StorageWriteErrors = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_WRITE_ERRORS); StorageActivateErrors = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_ACTIVATE_ERRORS); StorageReadLatency = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.STORAGE_READ_LATENCY); StorageWriteLatency = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.STORAGE_WRITE_LATENCY); StorageClearTotal = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_CLEAR_TOTAL); StorageClearErrors = CounterStatistic.FindOrCreate(StatisticNames.STORAGE_CLEAR_ERRORS); StorageClearLatency = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.STORAGE_CLEAR_LATENCY); }
public async Task OnTimerTick(AverageTimeSpanStatistic tardinessStat, Logger Logger) { var before = DateTime.UtcNow; var status = TickStatus.NewStruct(firstTickTime, period, before); if (Logger.IsVerbose2) { Logger.Verbose2("Triggering tick for {0}, status {1}, now {2}", this.ToString(), status, before); } try { if (null != stopwatch) { stopwatch.Stop(); var tardiness = stopwatch.Elapsed - period; tardinessStat.AddSample(Math.Max(0, tardiness.Ticks)); } await remindable.ReceiveReminder(ReminderName, status); if (null == stopwatch) { stopwatch = new Stopwatch(); } stopwatch.Restart(); var after = DateTime.UtcNow; if (Logger.IsVerbose2) { Logger.Verbose2("Tick triggered for {0}, dt {1} sec, next@~ {2}", this.ToString(), (after - before).TotalSeconds, // the next tick isn't actually scheduled until we return control to // AsyncSafeTimer but we can approximate it by adding the period of the reminder // to the after time. after + period); } } catch (Exception exc) { var after = DateTime.UtcNow; Logger.Error( ErrorCode.RS_Tick_Delivery_Error, String.Format("Could not deliver reminder tick for {0}, next {1}.", this.ToString(), after + period), exc); // What to do with repeated failures to deliver a reminder's ticks? } }
internal LocalReminderService( Silo silo, GrainId id, IReminderTable reminderTable, GlobalConfiguration config, TimeSpan initTimeout) : base(id, silo, null) { localReminders = new Dictionary <ReminderIdentity, LocalReminderData>(); this.reminderTable = reminderTable; this.config = config; this.initTimeout = initTimeout; localTableSequence = 0; tardinessStat = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.REMINDERS_AVERAGE_TARDINESS_SECONDS); IntValueStatistic.FindOrCreate(StatisticNames.REMINDERS_NUMBER_ACTIVE_REMINDERS, () => localReminders.Count); ticksDeliveredStat = CounterStatistic.FindOrCreate(StatisticNames.REMINDERS_COUNTERS_TICKS_DELIVERED); startedTask = new TaskCompletionSource <bool>(); }
internal LocalReminderService( Silo silo, IReminderTable reminderTable, TimeSpan initTimeout, ILoggerFactory loggerFactory) : base(GetGrainId(), silo, loggerFactory) { this.timerLogger = loggerFactory.CreateLogger <GrainTimer>(); localReminders = new Dictionary <ReminderIdentity, LocalReminderData>(); this.reminderTable = reminderTable; this.initTimeout = initTimeout; localTableSequence = 0; this.loggerFactory = loggerFactory; tardinessStat = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.REMINDERS_AVERAGE_TARDINESS_SECONDS); IntValueStatistic.FindOrCreate(StatisticNames.REMINDERS_NUMBER_ACTIVE_REMINDERS, () => localReminders.Count); ticksDeliveredStat = CounterStatistic.FindOrCreate(StatisticNames.REMINDERS_COUNTERS_TICKS_DELIVERED); startedTask = new TaskCompletionSource <bool>(); this.logger = this.loggerFactory.CreateLogger <LocalReminderService>(); }
internal LocalReminderService( Silo silo, IReminderTable reminderTable, TimeSpan initTimeout, ILoggerFactory loggerFactory, IAsyncTimerFactory asyncTimerFactory) : base(SystemTargetGrainId.CreateGrainServiceGrainId(GrainInterfaceUtils.GetGrainClassTypeCode(typeof(IReminderService)), null, silo.SiloAddress), silo, loggerFactory) { localReminders = new Dictionary <ReminderIdentity, LocalReminderData>(); this.reminderTable = reminderTable; this.initTimeout = initTimeout; this.asyncTimerFactory = asyncTimerFactory; localTableSequence = 0; tardinessStat = AverageTimeSpanStatistic.FindOrCreate(StatisticNames.REMINDERS_AVERAGE_TARDINESS_SECONDS); IntValueStatistic.FindOrCreate(StatisticNames.REMINDERS_NUMBER_ACTIVE_REMINDERS, () => localReminders.Count); ticksDeliveredStat = CounterStatistic.FindOrCreate(StatisticNames.REMINDERS_COUNTERS_TICKS_DELIVERED); startedTask = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); this.logger = loggerFactory.CreateLogger <LocalReminderService>(); this.listRefreshTimer = asyncTimerFactory.Create(Constants.RefreshReminderList, "ReminderService.ReminderListRefresher"); }
public static int WriteCounters() { if (logger.IsVerbose) { logger.Verbose("Writing counters."); } int numWriteErrors = 0; List <ICounter> allCounters = new List <ICounter>(); CounterStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); IntValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); StringValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); FloatValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); AverageTimeSpanStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); foreach (ICounter counter in allCounters) { try { if (logger.IsVerbose3) { logger.Verbose3(ErrorCode.PerfCounterWriting, "Writing counter {0}", counter.Name); } counter.TrackMetric(logger); } catch (Exception ex) { numWriteErrors++; logger.Error(ErrorCode.PerfCounterUnableToWrite, $"Unable to write to counter '{counter.Name}'", ex); } } return(numWriteErrors); }
public static int WriteCounters(ITelemetryProducer telemetryProducer, ILogger logger) { if (logger.IsEnabled(LogLevel.Trace)) { logger.LogTrace("Writing counters"); } int numWriteErrors = 0; List <ICounter> allCounters = new List <ICounter>(); CounterStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); IntValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); StringValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); FloatValueStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); AverageTimeSpanStatistic.AddCounters(allCounters, cs => cs.Storage != CounterStorage.DontStore); foreach (ICounter counter in allCounters) { try { if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace(ErrorCode.PerfCounterWriting, "Writing counter {0}", counter.Name); } counter.TrackMetric(telemetryProducer); } catch (Exception ex) { numWriteErrors++; logger.Error(ErrorCode.PerfCounterUnableToWrite, $"Unable to write to counter '{counter.Name}'", ex); } } return(numWriteErrors); }