internal Dispatcher( OrleansTaskScheduler scheduler, ISiloMessageCenter transport, Catalog catalog, ClusterConfiguration config, PlacementDirectorsManager placementDirectorsManager, ILocalGrainDirectory localGrainDirectory, MessageFactory messagefactory, SerializationManager serializationManager, CompatibilityDirectorManager compatibilityDirectorManager, ILoggerFactory loggerFactory) { this.loggerFactory = loggerFactory; this.scheduler = scheduler; this.catalog = catalog; Transport = transport; this.config = config; this.invokeWorkItemLogger = loggerFactory.CreateLogger <InvokeWorkItem>(); this.placementDirectorsManager = placementDirectorsManager; this.localGrainDirectory = localGrainDirectory; this.messagefactory = messagefactory; this.serializationManager = serializationManager; this.compatibilityDirectorManager = compatibilityDirectorManager; logger = new LoggerWrapper <Dispatcher>(loggerFactory); random = new SafeRandom(); }
internal Dispatcher( OrleansTaskScheduler scheduler, ISiloMessageCenter transport, Catalog catalog, ClusterConfiguration config, PlacementDirectorsManager placementDirectorsManager, ILocalGrainDirectory localGrainDirectory, MessageFactory messagefactory, SerializationManager serializationManager, CompatibilityDirectorManager compatibilityDirectorManager) { this.scheduler = scheduler; this.catalog = catalog; Transport = transport; this.config = config; this.placementDirectorsManager = placementDirectorsManager; this.localGrainDirectory = localGrainDirectory; this.messagefactory = messagefactory; this.serializationManager = serializationManager; this.compatibilityDirectorManager = compatibilityDirectorManager; logger = LogManager.GetLogger("Dispatcher", LoggerType.Runtime); rejectionInjectionRate = config.Globals.RejectionInjectionRate; double messageLossInjectionRate = config.Globals.MessageLossInjectionRate; errorInjection = rejectionInjectionRate > 0.0d || messageLossInjectionRate > 0.0d; errorInjectionRate = rejectionInjectionRate + messageLossInjectionRate; random = new SafeRandom(); }
internal PersistentStreamPullingAgent( GrainId id, string strProviderName, IStreamProviderRuntime runtime, QueueId queueId, TimeSpan queueGetPeriod, TimeSpan initQueueTimeout, TimeSpan maxDeliveryTime) : base(id, runtime.ExecutingSiloAddress, true) { if (runtime == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null"); if (strProviderName == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null"); QueueId = queueId; streamProviderName = strProviderName; providerRuntime = runtime; pubSub = runtime.PubSub(StreamPubSubType.GrainBased); pubSubCache = new Dictionary<StreamId, StreamConsumerCollection>(); safeRandom = new SafeRandom(); this.queueGetPeriod = queueGetPeriod; this.initQueueTimeout = initQueueTimeout; this.maxDeliveryTime = maxDeliveryTime; numMessages = 0; logger = providerRuntime.GetLogger(GrainId + "-" + streamProviderName); logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01, "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.", GetType().Name, GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode()); numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, strProviderName)); numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, strProviderName)); }
internal PersistentStreamPullingAgent( GrainId id, string strProviderName, IStreamProviderRuntime runtime, IStreamPubSub streamPubSub, QueueId queueId, PersistentStreamProviderConfig config) : base(id, runtime.ExecutingSiloAddress, true) { if (runtime == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null"); if (strProviderName == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null"); QueueId = queueId; streamProviderName = strProviderName; providerRuntime = runtime; pubSub = streamPubSub; pubSubCache = new Dictionary<StreamId, StreamConsumerCollection>(); safeRandom = new SafeRandom(); this.config = config; numMessages = 0; logger = providerRuntime.GetLogger(GrainId + "-" + streamProviderName); logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01, "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.", GetType().Name, GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode()); string statUniquePostfix = strProviderName + "." + QueueId; numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, statUniquePostfix)); numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, statUniquePostfix)); IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_PUBSUB_CACHE_SIZE, statUniquePostfix), () => pubSubCache.Count); // TODO: move queue cache size statistics tracking into queue cache implementation once Telemetry APIs and LogStatistics have been reconciled. //IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_QUEUE_CACHE_SIZE, statUniquePostfix), () => queueCache != null ? queueCache.Size : 0); }
internal Dispatcher( OrleansTaskScheduler scheduler, ISiloMessageCenter transport, Catalog catalog, IOptions <SiloMessagingOptions> messagingOptions, PlacementDirectorsManager placementDirectorsManager, ILocalGrainDirectory localGrainDirectory, MessageFactory messagefactory, SerializationManager serializationManager, CompatibilityDirectorManager compatibilityDirectorManager, ILoggerFactory loggerFactory, IOptions <SchedulingOptions> schedulerOptions) { this.scheduler = scheduler; this.catalog = catalog; Transport = transport; this.messagingOptions = messagingOptions.Value; this.invokeWorkItemLogger = loggerFactory.CreateLogger <InvokeWorkItem>(); this.placementDirectorsManager = placementDirectorsManager; this.localGrainDirectory = localGrainDirectory; this.messagefactory = messagefactory; this.serializationManager = serializationManager; this.compatibilityDirectorManager = compatibilityDirectorManager; this.schedulingOptions = schedulerOptions.Value; logger = loggerFactory.CreateLogger <Dispatcher>(); random = new SafeRandom(); }
public SingleStreamTestRunner(string streamProvider, int testNum = 0, bool fullTest = true) { this.streamProviderName = streamProvider; this.logger = TraceLogger.GetLogger("SingleStreamTestRunner", TraceLogger.LoggerType.Application); this.testNumber = testNum; this.runFullTest = fullTest; this.random = TestConstants.random; }
public static TimeSpan NextTimeSpan(this SafeRandom random, TimeSpan timeSpan) { if (timeSpan <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException("timeSpan", timeSpan, "SafeRandom.NextTimeSpan timeSpan must be a positive number."); } double ticksD = ((double)timeSpan.Ticks) * random.NextDouble(); long ticks = checked ((long)ticksD); return(TimeSpan.FromTicks(ticks)); }
public async Task AsyncSerialExecutorTests_Small() { AsyncSerialExecutor executor = new AsyncSerialExecutor(); List<Task> tasks = new List<Task>(); random = new SafeRandom(); operationsInProgress = 0; tasks.Add(executor.AddNext(() => Operation(1))); tasks.Add(executor.AddNext(() => Operation(2))); tasks.Add(executor.AddNext(() => Operation(3))); await Task.WhenAll(tasks); }
private void Start() { var random = new SafeRandom(); var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh); clientRefreshTimer = GrainTimer.FromTaskCallback( OnClientRefreshTimer, null, randomOffset, orleansConfig.Globals.ClientRegistrationRefresh, "ClientObserverRegistrar.ClientRefreshTimer"); clientRefreshTimer.Start(); if (logger.IsVerbose) { logger.Verbose("Client registrar service started successfully."); } }
public async Task AsyncSerialExecutorTests_SerialSubmit() { AsyncSerialExecutor executor = new AsyncSerialExecutor(); random = new SafeRandom(); List<Task> tasks = new List<Task>(); for (int i = 0; i < 10; i++) { int capture = i; logger.Info("Submitting Task {0}.", capture); tasks.Add(executor.AddNext(() => Operation(capture))); } await Task.WhenAll(tasks); }
public Task Start() { var random = new SafeRandom(); var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh); clientRefreshTimer = GrainTimer.FromTaskCallback( OnClientRefreshTimer, null, randomOffset, orleansConfig.Globals.ClientRegistrationRefresh, "ClientObserverRegistrar.ClientRefreshTimer"); clientRefreshTimer.Start(); return TaskDone.Done; }
public Task Start() { var random = new SafeRandom(); var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh); clientRefreshTimer = GrainTimer.FromTaskCallback( OnClientRefreshTimer, null, randomOffset, orleansConfig.Globals.ClientRegistrationRefresh, "ClientObserverRegistrar.ClientRefreshTimer"); clientRefreshTimer.Start(); return(TaskDone.Done); }
public static TimeSpan NextTimeSpan(this SafeRandom random, TimeSpan minValue, TimeSpan maxValue) { if (minValue <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException("minValue", minValue, "SafeRandom.NextTimeSpan minValue must be a positive number."); } if (minValue >= maxValue) { throw new ArgumentOutOfRangeException("minValue", minValue, "SafeRandom.NextTimeSpan minValue must be greater than maxValue."); } var span = maxValue - minValue; return(minValue + random.NextTimeSpan(span)); }
internal static async Task ReminderTableTest(IReminderTable reminderTable) { Guid guid = Guid.NewGuid(); var results = await Task.WhenAll(Enumerable.Range(0, 10). Select(x => reminderTable.UpsertRow(CreateReminder(MakeTestGrainReference(guid), "0")))); Assert.AreEqual(results.Distinct().Count(), results.Length); await Task.WhenAll(Enumerable.Range(1, 999).Select(async i => { GrainReference grainRef = MakeTestGrainReference(Guid.NewGuid()); await reminderTable.UpsertRow(CreateReminder(grainRef, i.ToString())); })); var rows = await reminderTable.ReadRows(0, uint.MaxValue); Assert.AreEqual(rows.Reminders.Count, 1000); rows = await reminderTable.ReadRows(0, 0); Assert.AreEqual(rows.Reminders.Count, 1000); var remindersHashes = rows.Reminders.Select(r => r.GrainRef.GetUniformHashCode()).ToArray(); SafeRandom random = new SafeRandom(); await Task.WhenAll(Enumerable.Repeat( TestRemindersHashInterval(reminderTable, (uint) random.Next(), (uint) random.Next(), remindersHashes), 1000)); var reminder = rows.Reminders.First(); var shouldExist = await reminderTable.ReadRow(reminder.GrainRef, reminder.ReminderName); Assert.IsNotNull(shouldExist); string etagTemp = reminder.ETag; reminder.ETag = await reminderTable.UpsertRow(reminder); var removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, etagTemp); Assert.IsFalse(removeRowRes, "should have failed. Etag is wrong"); removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, "bla", reminder.ETag); Assert.IsFalse(removeRowRes, "should have failed. reminder name is wrong"); removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag); Assert.IsTrue(removeRowRes, "should have succeeded. Etag is right"); removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag); Assert.IsFalse(removeRowRes, "should have failed. reminder shouldn't exist"); }
private void Start() { var random = new SafeRandom(); var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh); this.RegisterTimer( this.OnClientRefreshTimer, null, randomOffset, orleansConfig.Globals.ClientRegistrationRefresh, "ClientObserverRegistrar.ClientRefreshTimer"); if (logger.IsVerbose) { logger.Verbose("Client registrar service started successfully."); } }
public async Task Start() { logger.Info("Starting DeploymentLoadPublisher."); if (statisticsRefreshTime > TimeSpan.Zero) { var random = new SafeRandom(); // Randomize PublishStatistics timer, // but also upon start publish my stats to everyone and take everyone's stats for me to start with something. var randomTimerOffset = random.NextTimeSpan(statisticsRefreshTime); this.RegisterTimer(PublishStatistics, null, randomTimerOffset, statisticsRefreshTime, "DeploymentLoadPublisher.PublishStatisticsTimer"); } await RefreshStatistics(); await PublishStatistics(null); logger.Info("Started DeploymentLoadPublisher."); }
private void Start() { var random = new SafeRandom(); var randomOffset = random.NextTimeSpan(this.messagingOptions.ClientRegistrationRefresh); this.refreshTimer = this.RegisterTimer( this.OnClientRefreshTimer, null, randomOffset, this.messagingOptions.ClientRegistrationRefresh, "ClientObserverRegistrar.ClientRefreshTimer"); if (logger.IsEnabled(LogLevel.Debug)) { logger.Debug("Client registrar service started successfully."); } }
public async Task Start() { logger.Info("Starting DeploymentLoadPublisher."); if (statisticsRefreshTime > TimeSpan.Zero) { var random = new SafeRandom(); // Randomize PublishStatistics timer, // but also upon start publish my stats to everyone and take everyone's stats for me to start with something. var randomTimerOffset = random.NextTimeSpan(statisticsRefreshTime); var t = GrainTimer.FromTaskCallback(PublishStatistics, null, randomTimerOffset, statisticsRefreshTime, "DeploymentLoadPublisher.PublishStatisticsTimer"); t.Start(); } await RefreshStatistics(); await PublishStatistics(null); logger.Info("Started DeploymentLoadPublisher."); }
public Dispatcher( OrleansTaskScheduler scheduler, ISiloMessageCenter transport, Catalog catalog, ClusterConfiguration config) { Scheduler = scheduler; this.catalog = catalog; Transport = transport; this.config = config; logger = TraceLogger.GetLogger("Dispatcher", TraceLogger.LoggerType.Runtime); rejectionInjectionRate = config.Globals.RejectionInjectionRate; double messageLossInjectionRate = config.Globals.MessageLossInjectionRate; errorInjection = rejectionInjectionRate > 0.0d || messageLossInjectionRate > 0.0d; errorInjectionRate = rejectionInjectionRate + messageLossInjectionRate; random = new SafeRandom(); }
public GatewayManager(ClientConfiguration cfg, IGatewayListProvider gatewayListProvider) { config = cfg; knownDead = new Dictionary<Uri, DateTime>(); rand = new SafeRandom(); logger = TraceLogger.GetLogger("Messaging.GatewayManager", TraceLogger.LoggerType.Runtime); lockable = new object(); gatewayRefreshCallInitiated = false; ListProvider = gatewayListProvider; var knownGateways = ListProvider.GetGateways().GetResult(); if (knownGateways.Count == 0) { string gatewayProviderType = gatewayListProvider.GetType().FullName; string err = String.Format("Could not find any gateway in {0}. Orleans client cannot initialize.", gatewayProviderType); logger.Error(ErrorCode.GatewayManager_NoGateways, err); throw new OrleansException(err); } logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways)); if (ListProvider is IGatewayListObservable) { ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this); } roundRobinCounter = cfg.PreferedGatewayIndex >= 0 ? cfg.PreferedGatewayIndex : rand.Next(knownGateways.Count); cachedLiveGateways = knownGateways; lastRefreshTime = DateTime.UtcNow; if (ListProvider.IsUpdatable) { gatewayRefreshTimer = new SafeTimer(RefreshSnapshotLiveGateways_TimerCallback, null, config.GatewayListRefreshPeriod, config.GatewayListRefreshPeriod); } }
internal async Task RemindersRange(int iterations=1000) { await Task.WhenAll(Enumerable.Range(1, iterations).Select(async i => { GrainReference grainRef = MakeTestGrainReference(); await remindersTable.UpsertRow(CreateReminder(grainRef, i.ToString())); })); var rows = await remindersTable.ReadRows(0, uint.MaxValue); Assert.AreEqual(rows.Reminders.Count, iterations); rows = await remindersTable.ReadRows(0, 0); Assert.AreEqual(rows.Reminders.Count, iterations); var remindersHashes = rows.Reminders.Select(r => r.GrainRef.GetUniformHashCode()).ToArray(); SafeRandom random = new SafeRandom(); await Task.WhenAll(Enumerable.Range(0, iterations).Select(i => TestRemindersHashInterval(remindersTable, (uint)random.Next(), (uint)random.Next(), remindersHashes))); }
public async Task InterleavingConsistencyTest(int numItems) { TimeSpan delay = TimeSpan.FromMilliseconds(1); SafeRandom random = new SafeRandom(); List<Task> getFileMetadataPromises = new List<Task>(numItems*2); Dictionary<int, string> fileMetadatas = new Dictionary<int, string>(numItems*2); for (int i = 0; i < numItems; i++) { int capture = i; Func<Task> func = ( async () => { await Task.Delay(random.NextTimeSpan(delay)); int fileMetadata = capture; if ((fileMetadata%2) == 0) { fileMetadatas.Add(fileMetadata, fileMetadata.ToString()); } }); getFileMetadataPromises.Add(func()); } await Task.WhenAll(getFileMetadataPromises.ToArray()); List<Task> tagPromises = new List<Task>(fileMetadatas.Count); foreach (KeyValuePair<int, string> keyValuePair in fileMetadatas) { int fileId = keyValuePair.Key; Func<Task> func = (async () => { await Task.Delay(random.NextTimeSpan(delay)); string fileMetadata = fileMetadatas[fileId]; }); tagPromises.Add(func()); } await Task.WhenAll(tagPromises); // sort the fileMetadatas according to fileIds. List<string> results = new List<string>(fileMetadatas.Count); for (int i = 0; i < numItems; i++) { string metadata; if (fileMetadatas.TryGetValue(i, out metadata)) { results.Add(metadata); } } if (numItems != results.Count) { //throw new OrleansException(String.Format("numItems != results.Count, {0} != {1}", numItems, results.Count)); } }
private static Task<bool>[] InsertAndReadStreamsAndCheckMatch(RelationalStorageForTesting sut, int streamSize, int countOfStreams, CancellationToken cancellationToken) { //Stream in and steam out three binary streams in parallel. var streamChecks = new Task<bool>[countOfStreams]; var sr = new SafeRandom(); for(int i = 0; i < countOfStreams; ++i) { int streamId = i; streamChecks[i] = Task.Run(async () => { var rb = new byte[streamSize]; sr.NextBytes(rb); await InsertIntoDatabaseUsingStream(sut, streamId, rb, cancellationToken); var dataStreamFromTheDb = await ReadFromDatabaseUsingAsyncStream(sut, streamId, cancellationToken); return dataStreamFromTheDb.StreamData.SequenceEqual(rb); }); } return streamChecks; }