diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-19 12:53:17 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-19 12:53:17 -0600 |
| commit | 6fdc317978fd91fbfd5828ee72c7e7f19c316b13 (patch) | |
| tree | 0370a03f1fadda7e6d4979cb4ee46c4d75880e8d /src/slskd/Core | |
| parent | 9c1c726f2de69dd3fd38740f5bdb7f1f76e97fcf (diff) | |
| parent | 5b302ae5f2e0c01cb111a37680d63df3d47b114d (diff) | |
| download | slskd-6fdc317978fd91fbfd5828ee72c7e7f19c316b13.tar.gz | |
Merge pull request #1608 from slskd/search-metrics
Add throttling for incoming search requests, add additional prometheus metrics covering search responses
Diffstat (limited to 'src/slskd/Core')
| -rw-r--r-- | src/slskd/Core/Clock.cs | 10 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 61 | ||||
| -rw-r--r-- | src/slskd/Core/State.cs | 18 |
3 files changed, 89 insertions, 0 deletions
diff --git a/src/slskd/Core/Clock.cs b/src/slskd/Core/Clock.cs index 1563a895..a111f40d 100644 --- a/src/slskd/Core/Clock.cs +++ b/src/slskd/Core/Clock.cs @@ -29,6 +29,7 @@ namespace slskd static Clock() { EveryMinuteTimer.Elapsed += (_, _) => Fire(EveryMinute); + EveryThirtySecondsTimer.Elapsed += (_, _) => Fire(EveryThirtySeconds); EveryFiveMinutesTimer.Elapsed += (_, _) => Fire(EveryFiveMinutes); EveryThirtyMinutesTimer.Elapsed += (_, _) => Fire(EveryThirtyMinutes); EveryHourTimer.Elapsed += (_, _) => Fire(EveryHour); @@ -50,6 +51,11 @@ namespace slskd public static event EventHandler<ClockEventArgs> EveryMinute; /// <summary> + /// Fires every 30 seconds. + /// </summary> + public static event EventHandler<ClockEventArgs> EveryThirtySeconds; + + /// <summary> /// Fires every 30 minutes. /// </summary> public static event EventHandler<ClockEventArgs> EveryThirtyMinutes; @@ -57,6 +63,7 @@ namespace slskd private static Timer EveryFiveMinutesTimer { get; } = CreateTimer(interval: 1000 * 60 * 5); private static Timer EveryHourTimer { get; } = CreateTimer(interval: 1000 * 60 * 60); private static Timer EveryMinuteTimer { get; } = CreateTimer(interval: 1000 * 60); + private static Timer EveryThirtySecondsTimer { get; } = CreateTimer(interval: 1000 * 30); private static Timer EveryThirtyMinutesTimer { get; } = CreateTimer(interval: 1000 * 60 * 30); /// <summary> @@ -66,6 +73,7 @@ namespace slskd public static Task StartAsync() { EveryMinuteTimer.Enabled = true; + EveryThirtySecondsTimer.Enabled = true; EveryFiveMinutesTimer.Enabled = true; EveryThirtyMinutesTimer.Enabled = true; EveryHourTimer.Enabled = true; @@ -74,6 +82,7 @@ namespace slskd return Task.WhenAll( Task.Run(() => Fire(EveryMinute, firstRunArgs)), + Task.Run(() => Fire(EveryThirtySeconds, firstRunArgs)), Task.Run(() => Fire(EveryFiveMinutes, firstRunArgs)), Task.Run(() => Fire(EveryThirtyMinutes, firstRunArgs)), Task.Run(() => Fire(EveryHour, firstRunArgs))); @@ -85,6 +94,7 @@ namespace slskd public static void Stop() { EveryMinuteTimer.Stop(); + EveryThirtySecondsTimer.Stop(); EveryFiveMinutesTimer.Stop(); EveryThirtyMinutesTimer.Stop(); EveryHourTimer.Stop(); diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 68fa4d92..200b0ee8 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -283,6 +283,12 @@ namespace slskd public RetentionOptions Retention { get; init; } = new RetentionOptions(); /// <summary> + /// Gets throttling options. + /// </summary> + [Validate] + public ThrottlingOptions Throttling { get; init; } = new ThrottlingOptions(); + + /// <summary> /// Gets logger options. /// </summary> [Validate] @@ -1462,6 +1468,61 @@ namespace slskd } /// <summary> + /// Throttling options. + /// </summary> + public class ThrottlingOptions + { + /// <summary> + /// Gets search throttling options. + /// </summary> + [Validate] + public SearchThrottlingOptions Search { get; init; } = new SearchThrottlingOptions(); + + /// <summary> + /// Search throttling options. + /// </summary> + public class SearchThrottlingOptions + { + /// <summary> + /// Gets incoming search throttling options. + /// </summary> + [Validate] + public IncomingSearchThrottlingOptions Incoming { get; init; } = new IncomingSearchThrottlingOptions(); + + /// <summary> + /// Search response throttling options. + /// </summary> + public class IncomingSearchThrottlingOptions + { + /// <summary> + /// Gets the limit for the number of concurrent search response operations. + /// </summary> + [Argument(default, "throttling-search-incoming-concurrency")] + [EnvironmentVariable("THROTTLING_SEARCH_INCOMING_CONCURRENCY")] + [Range(1, 100)] + [RequiresRestart] + public int Concurrency { get; init; } = 10; + + /// <summary> + /// Gets the limit for the number of queued search response operations, after which requests will be discarded. + /// </summary> + [Argument(default, "throttling-search-incoming-circuit-breaker")] + [EnvironmentVariable("THROTTLING_SEARCH_INCOMING_CIRCUIT_BREAKER")] + [Range(100, 10000)] + public int CircuitBreaker { get; init; } = 500; + + /// <summary> + /// Gets the limit for the number of files that can be returned in a single search request. + /// </summary> + [Argument(default, "throttling-search-incoming-response-file-limit")] + [EnvironmentVariable("THROTTLING_SEARCH_INCOMING_RESPONSE_FILE_LIMIT")] + [Range(100, 5000)] + public int ResponseFileLimit { get; init; } = 500; + } + } + } + + /// <summary> /// Metrics options. /// </summary> public class MetricsOptions diff --git a/src/slskd/Core/State.cs b/src/slskd/Core/State.cs index 86b628b5..4f7876de 100644 --- a/src/slskd/Core/State.cs +++ b/src/slskd/Core/State.cs @@ -37,6 +37,7 @@ namespace slskd public ServerState Server { get; init; } = new ServerState(); public ServerConnectionWatchdogState ConnectionWatchdog { get; init; } = new ServerConnectionWatchdogState(); public RelayState Relay { get; init; } = new RelayState(); + public HealthState Health { get; init; } = new HealthState(); public UserState User { get; init; } = new UserState(); public DistributedNetworkState DistributedNetwork { get; init; } = new DistributedNetworkState(); public ShareState Shares { get; init; } = new ShareState(); @@ -44,6 +45,23 @@ namespace slskd public User[] Users { get; init; } = Array.Empty<User>(); } + public record HealthState + { + public SearchHealthState Search { get; init; } = new(); + + public record SearchHealthState + { + public IncomingSearchHealthState Incoming { get; init; } = new(); + + public record IncomingSearchHealthState + { + public double Latency { get; init; } + public int QueueDepth { get; init; } + public double DropRate { get; init; } + } + } + } + public record VersionState { public string Full { get; init; } = Program.FullVersion; |
