Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threadpool diagnostics #1811

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Proto.Actor/ActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private void RunThreadPoolStats()

logger.LogWarning("System {Id} - ThreadPool is running hot, ThreadPool latency {ThreadPoolLatency}", Id,
t);

}, Stopper.Token
);
}
Expand Down
30 changes: 28 additions & 2 deletions src/Proto.Actor/Diagnostics/DiagnosticsStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Text.Json.Serialization;
using System.Threading;
using Microsoft.Extensions.Logging;
using Proto.Utils;

Expand All @@ -14,14 +16,38 @@ public class DiagnosticsStore
public DiagnosticsStore(ActorSystem system)
{
_logLevel = system.Config.DiagnosticsLogLevel;
RegisterEnvironmentSettings();
}

private void RegisterEnvironmentSettings()
{
ThreadPool.GetMinThreads(out var minWorkerThreads, out var minCompletionPortThreads);
ThreadPool.GetAvailableThreads(out var availableWorkerThreads, out var availableCompletionPortThreads);
var cpuCount = Environment.ProcessorCount;
var dotnetVersion = Environment.Version;
var platform = Environment.OSVersion.Platform;
var platformVersion = Environment.OSVersion.VersionString;
var stats = new
{
cpuCount,
dotnetVersion,
platform,
platformVersion,
minWorkerThreads,
minCompletionPortThreads,
availableWorkerThreads,
availableCompletionPortThreads,
};

RegisterObject("Environment", "Settings", stats);
}

public void RegisterEvent(string module, string message)
{
var entry = new DiagnosticsEntry(module, message, null);
if (_entries.TryAdd(entry))
{
_logger.Log(_logLevel, "[Diagnostics] Event {Module}: {Message}", module, message);
_logger.Log(_logLevel, "[Diagnostics] {Module}: {Message}", module, message);
}
}

Expand All @@ -32,7 +58,7 @@ public void RegisterObject(string module, string key, object data)
if (_entries.TryAdd(entry))
{
var json = System.Text.Json.JsonSerializer.Serialize(data);
_logger.Log(_logLevel,"[Diagnostics] Event {Module}: {Key}: {Data}", module, key, json);
_logger.Log(_logLevel,"[Diagnostics] {Module}: {Key}: {Data}", module, key, json);
}
}

Expand Down