/// <summary> /// Start stats collection /// </summary> public void Start() { logger.Info(ErrorCode.PerfCounterStarting, "Starting Windows perf counter stats collection with frequency={0}", PerfCountersWriteInterval); Prepare(); // Start the timer timer = new SafeTimer(TimerTick, null, PerfCountersWriteInterval, PerfCountersWriteInterval); }
/// <summary> /// Stop stats collection /// </summary> public void Stop() { logger.Info(ErrorCode.PerfCounterStopping, "Stopping Windows perf counter stats collection"); if (timer != null) timer.Dispose(); // Stop timer timer = null; }
internal void Start() { running = true; systemThread.Start(); foreach (WorkerPoolThread t in pool) t.Start(); if (InjectMoreWorkerThreads) longTurnTimer = new SafeTimer(obj => CheckForLongTurns(), null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }
internal WorkerPool(OrleansTaskScheduler sched, int maxActiveThreads, bool injectMoreWorkerThreads) { scheduler = sched; MaxActiveThreads = maxActiveThreads; InjectMoreWorkerThreads = injectMoreWorkerThreads; MaxWorkQueueWait = TimeSpan.FromMilliseconds(50); threadLimitingSemaphore = new Semaphore(maxActiveThreads, maxActiveThreads); pool = new HashSet<WorkerPoolThread>(); lockable = new object(); for (int i = 0; i < MaxActiveThreads; i++) { var t = new WorkerPoolThread(this, scheduler); pool.Add(t); } systemThread = new WorkerPoolThread(this, scheduler, true); running = false; runningThreadCount = 0; longTurnTimer = null; }
internal void Stop() { running = false; if (longTurnTimer != null) { longTurnTimer.Dispose(); longTurnTimer = null; } WorkerPoolThread[] threads; lock (lockable) { threads = pool.ToArray<WorkerPoolThread>(); } foreach (WorkerPoolThread thread in threads) thread.Stop(); systemThread.Stop(); }
internal WorkerPool(OrleansTaskScheduler sched, int maxActiveThreads, bool enableWorkerThreadInjection) { scheduler = sched; MaxActiveThreads = maxActiveThreads; EnableWorkerThreadInjection = enableWorkerThreadInjection; MaxWorkQueueWait = TimeSpan.FromMilliseconds(50); if (EnableWorkerThreadInjection) { threadLimitingSemaphore = new Semaphore(maxActiveThreads, maxActiveThreads); } pool = new HashSet<WorkerPoolThread>(); createThreadCount = 0; lockable = new object(); for (createThreadCount = 0; createThreadCount < MaxActiveThreads; createThreadCount++) { var t = new WorkerPoolThread(this, scheduler, createThreadCount); pool.Add(t); } createThreadCount++; systemThread = new WorkerPoolThread(this, scheduler, createThreadCount, true); running = false; runningThreadCount = 0; longTurnTimer = null; }
public Task OnStop(CancellationToken ct) { cpuUsageTimer?.Dispose(); cpuUsageTimer = null; return(Task.CompletedTask); }
public Task OnStart(CancellationToken ct) { if (!countersAvailable) { logger.Warn(ErrorCode.PerfCounterNotRegistered, "CPU & Memory perf counters did not initialize correctly - try repairing Windows perf counter config on this machine with 'lodctr /r' command"); } if (cpuCounterPF != null) { cpuUsageTimer = new SafeTimer(this.logger, CheckCpuUsage, null, CPU_CHECK_PERIOD, CPU_CHECK_PERIOD); } try { if (cpuCounterPF != null) { // Read initial value of CPU Usage counter CpuUsage = cpuCounterPF.NextValue(); } } catch (InvalidOperationException) { // Can sometimes get exception accessing CPU Usage counter for first time in some runtime environments CpuUsage = 0; } FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_CPUUSAGE, () => CpuUsage.Value); IntValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_TOTALMEMORYKB, () => (long)((MemoryUsage + KB - 1.0) / KB)); // Round up #if LOG_MEMORY_PERF_COUNTERS // print GC stats in the silo log file. StringValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_GENCOLLECTIONCOUNT, () => GCGenCollectionCount); StringValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_GENSIZESKB, () => GCGenSizes); if (timeInGCPF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_PERCENTOFTIMEINGC, () => timeInGCPF.NextValue()); } if (allocatedBytesPerSecPF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_ALLOCATEDBYTESINKBPERSEC, () => allocatedBytesPerSecPF.NextValue() / KB); } if (promotedMemoryFromGen1PF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_PROMOTEDMEMORYFROMGEN1KB, () => promotedMemoryFromGen1PF.NextValue() / KB); } if (largeObjectHeapSizePF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_LARGEOBJECTHEAPSIZEKB, () => largeObjectHeapSizePF.NextValue() / KB); } if (promotedFinalizationMemoryFromGen0PF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_PROMOTEDMEMORYFROMGEN0KB, () => promotedFinalizationMemoryFromGen0PF.NextValue() / KB); } if (numberOfInducedGCsPF != null) { FloatValueStatistic.FindOrCreate(StatisticNames.RUNTIME_GC_NUMBEROFINDUCEDGCS, () => numberOfInducedGCsPF.NextValue()); } IntValueStatistic.FindOrCreate(StatisticNames.RUNTIME_MEMORY_TOTALPHYSICALMEMORYMB, () => (long)((TotalPhysicalMemory / KB) / KB)); if (availableMemoryCounterPF != null) { IntValueStatistic.FindOrCreate(StatisticNames.RUNTIME_MEMORY_AVAILABLEMEMORYMB, () => (long)((AvailableMemory / KB) / KB)); // Round up } #endif IntValueStatistic.FindOrCreate(StatisticNames.RUNTIME_DOT_NET_THREADPOOL_INUSE_WORKERTHREADS, () => { ThreadPool.GetMaxThreads(out var maXworkerThreads, out var maXcompletionPortThreads); // GetAvailableThreads Retrieves the difference between the maximum number of thread pool threads // and the number currently active. // So max-Available is the actual number in use. If it goes beyond min, it means we are stressing the thread pool. ThreadPool.GetAvailableThreads(out var workerThreads, out var completionPortThreads); return(maXworkerThreads - workerThreads); }); IntValueStatistic.FindOrCreate(StatisticNames.RUNTIME_DOT_NET_THREADPOOL_INUSE_COMPLETIONPORTTHREADS, () => { ThreadPool.GetMaxThreads(out var maxWorkerThreads, out var maxCompletionPortThreads); ThreadPool.GetAvailableThreads(out var workerThreads, out var completionPortThreads); return(maxCompletionPortThreads - completionPortThreads); }); return(Task.CompletedTask); }
internal void ConsumeServices(IServiceProvider services) { try { AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; this.ServiceProvider = services; var connectionLostHandlers = this.ServiceProvider.GetServices <ConnectionToClusterLostHandler>(); foreach (var handler in connectionLostHandlers) { this.ClusterConnectionLost += handler; } var gatewayCountChangedHandlers = this.ServiceProvider.GetServices <GatewayCountChangedHandler>(); foreach (var handler in gatewayCountChangedHandlers) { this.GatewayCountChanged += handler; } var clientInvokeCallbacks = this.ServiceProvider.GetServices <ClientInvokeCallback>(); foreach (var handler in clientInvokeCallbacks) { this.ClientInvokeCallback += handler; } this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>(); this.ClientStatistics = this.ServiceProvider.GetRequiredService <ClientStatisticsManager>(); this.messageFactory = this.ServiceProvider.GetService <MessageFactory>(); var serializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>(); this.localObjects = new InvokableObjectManager( this, serializationManager, this.loggerFactory.CreateLogger <InvokableObjectManager>()); var timerLogger = this.loggerFactory.CreateLogger <SafeTimer>(); var minTicks = Math.Min(this.clientMessagingOptions.ResponseTimeout.Ticks, TimeSpan.FromSeconds(1).Ticks); var period = TimeSpan.FromTicks(minTicks); this.callbackTimer = new SafeTimer(timerLogger, this.OnCallbackExpiryTick, null, period, period); this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>(); BufferPool.InitGlobalBufferPool(this.clientMessagingOptions); this.clientProviderRuntime = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>(); this.localAddress = this.clientMessagingOptions.LocalAddress ?? ConfigUtilities.GetLocalIPAddress(this.clientMessagingOptions.PreferredFamily, this.clientMessagingOptions.NetworkInterfaceName); // Client init / sign-on message logger.Info(ErrorCode.ClientInitializing, string.Format( "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}", BARS, Dns.GetHostName(), localAddress, handshakeClientId)); string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}", BARS, RuntimeVersion.Current, PrintAppDomainDetails()); logger.Info(ErrorCode.ClientStarting, startMsg); if (TestOnlyThrowExceptionDuringInit) { throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit"); } this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>(); var statisticsLevel = statisticsOptions.Value.CollectionLevel; if (statisticsLevel.CollectThreadTimeTrackingStats()) { incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver", this.loggerFactory, this.statisticsOptions, this.schedulerStageStatistics); } } catch (Exception exc) { if (logger != null) { logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc); } ConstructorReset(); throw; } }
public void OnStart(GameInterface game) { this.game = game; currentZone = 0; (timer = this.CreateTimer(50, game, Timer_OnElapsed)).Start(); }