Skip to content

Add throttling for incoming search requests, add additional prometheus metrics covering search responses#1608

Merged
jpdillingham merged 26 commits into
masterfrom
search-metrics
Jan 19, 2026
Merged

Add throttling for incoming search requests, add additional prometheus metrics covering search responses#1608
jpdillingham merged 26 commits into
masterfrom
search-metrics

Conversation

@jpdillingham

@jpdillingham jpdillingham commented Jan 18, 2026

Copy link
Copy Markdown
Member

Throttling

Warning

Application Stability Risk: The options in this section control the behavior of the application at the limits of the hosting environment's performance. Increasing values can result in unintended behavior and crashes. Support for users that increase these values will be limited.

slskd is a multi-threaded application and the logic is highly concurrent, but is mostly bound by disk and network I/O rather than CPU.

The concurrency option controls how many threads (.NET Tasks to be specific) can perform work at the same time, limiting I/O contention. Raising the number can improve throughput on capable machines but defaults are generally set in such a way that improvements will be negligible. Lowering the number will reduce throughput but alleviate I/O contention and improve stability on lower-spec hardware.

Lower values of concurrency or slow processing of individual messages may cause the application to process messages at a slower rate than they are received, causing messages to be 'backed up' in internal queues. The circuit_breaker option controls the number of messages that can be enqueued. Once the circuit breaker is hit, the application will drop or discard messages without processing them.

The latency, queue depth and rate at which messages are being dropped can be monitored by reviewing the application state or Prometheus metrics.

Command Line Environment Variable Description
--throttling-search-incoming-concurrency SLSKD_THROTTING_SEARCH_INCOMING_CONCURRENCY The limit for the number of concurrent search response operations
--throttling-search-incoming-circuit-breaker SLSKD_THROTTING_SEARCH_INCOMING_CIRCUIT_BREAKER The limit for the number of queued search response operations, after which requests will be discarded
--throttling-search-incoming-response-file-limit SLSKD_THROTTING_SEARCH_INCOMING_RESPONSE_FILE_LIMIT The limit for the number of files that can be returned in a single search request

YAML

throttling:
  search:
    incoming:
      concurrency: 10 # number of search requests to process at the same time
      circuit_breaker: 500 # maximum number of pending search requests
      file_limit: 500 # maximum number of files to return in a single search response

Additional Metrics

Search Requests

  • slskd_search_incoming_requests_received - Total number of search requests received
  • slskd_search_incoming_request_receive_rate_current - Number of search requests received in the last minute
  • slskd_search_incoming_requests_dropped - Total number of search requests dropped due to processing pressure
  • slskd_search_incoming_request_drop_rate_current - Number of search requests dropped in the last minute
  • slskd_search_incoming_request_queue_depth_current - The number of incoming search requests waiting to be processed

Search Responses

  • slskd_search_incoming_responses_sent - Total number of search responses sent
  • slskd_search_incoming_response_send_rate_current - Number of search responses sent in the last minute

Search Response Latency

The time it is taking to respond to incoming search requests. The ideal rate is something under ~30ms, or dropped requests become likely.

The response_latency metric is a measure of the total time, from receipt of the request until the response is returned. The remaining metrics measure different components of the overall latency.

  • slskd_search_incoming_response_latency - The time taken to resolve and return a response to an incoming search request, in milliseconds
  • slskd_search_incoming_response_latency_current - The average time taken to resolve and return a response to an incoming search request, in milliseconds
  • slskd_search_incoming_filter_latency - The time taken to apply filters to an incoming search request, in milliseconds
  • slskd_search_incoming_filter_latency_current - The average time taken to apply filters to an incoming search request, in milliseconds
  • slskd_search_incoming_query_latency - The time taken to query share database(s) for results, in milliseconds
  • slskd_search_incoming_query_latency_current - The average time taken to query share database(s) for results, in milliseconds

@jpdillingham jpdillingham changed the title Add additional prometheus metrics covering search responses Add throttling for incoming search requests, add additional prometheus metrics covering search responses Jan 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds throttling capabilities for incoming search requests to prevent memory exhaustion under high load, along with comprehensive Prometheus metrics for monitoring search performance. The changes introduce configurable concurrency limits, circuit breaker thresholds, and response file limits.

Changes:

  • Added throttling options with semaphore-based concurrency control and circuit breaker for incoming search requests
  • Introduced detailed Prometheus metrics tracking search request rates, response times, queue depth, and drop rates
  • Extended search interfaces to support optional row limits for database queries

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/slskd/Telemetry/Metrics.cs Restructured metrics into nested Incoming, Filter, and Query classes with new counters, gauges, and histograms for comprehensive search monitoring
src/slskd/Shares/SqliteShareRepository.cs Added optional limit parameter to Search method for SQL LIMIT clause support
src/slskd/Shares/ShareService.cs Added optional limit parameter to SearchAsync and passed through to repositories
src/slskd/Shares/IShareService.cs Updated interface to include optional limit parameter
src/slskd/Shares/IShareRepository.cs Updated interface to include optional limit parameter
src/slskd/Core/State.cs Added HealthState with nested structure for tracking search health metrics (latency, queue depth, drop rate)
src/slskd/Core/Options.cs Added ThrottlingOptions with nested classes for configuring search concurrency, circuit breaker, and response file limits
src/slskd/Core/Clock.cs Added EveryThirtySeconds timer for health state updates
src/slskd/Application.cs Implemented semaphore-based throttling, circuit breaker logic, and detailed metric tracking in SearchResponseResolver
docs/config.md Added documentation for new throttling options with configuration table and YAML examples
config/slskd.example.yml Added commented example configuration for throttling options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/slskd/Application.cs
Comment thread src/slskd/Application.cs
Comment thread docs/config.md Outdated
Comment thread docs/config.md Outdated
Comment thread src/slskd/Application.cs Outdated
Comment thread src/slskd/Telemetry/Metrics.cs Outdated
Comment thread src/slskd/Shares/ShareService.cs
Comment thread src/slskd/Core/Options.cs
Comment thread src/slskd/Application.cs
Comment thread src/slskd/Application.cs
jpdillingham and others added 6 commits January 19, 2026 12:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jpdillingham jpdillingham merged commit 6fdc317 into master Jan 19, 2026
6 checks passed
@jpdillingham jpdillingham deleted the search-metrics branch January 19, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants