Skip to content

[MOD-12694] [MOD-12069] Add active_worker_threads metric#7538

Merged
meiravgri merged 10 commits intomasterfrom
meiravg_active_threads
Nov 27, 2025
Merged

[MOD-12694] [MOD-12069] Add active_worker_threads metric#7538
meiravgri merged 10 commits intomasterfrom
meiravg_active_threads

Conversation

@meiravgri
Copy link
Collaborator

@meiravgri meiravgri commented Nov 26, 2025

Extends the multi_threading section in INFO MODULES by adding search_active_worker_threads metric to track currently executing worker thread queries.

Continues #7530 which added search_multi_threading section and search_active_io_threads field.

INFO MODULES Output

# search_multi_threading
...
search_active_worker_threads:0

Note

Expose current worker thread activity via search_active_worker_threads in INFO MODULES alongside existing I/O stats.

  • Metrics/INFO MODULES:
    • Extend multi_threading with active_worker_threads in src/info/info_redis/info_redis.c using GlobalStats_GetMultiThreadingStats().
  • Global stats:
    • Add active_worker_threads to MultiThreadingStats (src/info/global_stats.h).
    • Populate via workersThreadPool_WorkingThreadCount() with safety assert workersThreadPool_isCreated() (src/info/global_stats.c).
  • Workers utility:
    • Add workersThreadPool_isCreated() API (src/util/workers.{h,c}).
  • Tests:
    • Add SA and cluster tests validating search_multi_threading.search_active_worker_threads behavior with paused queries (tests/pytests/test_info_modules.py).

Written by Cursor Bugbot for commit 399bb53. This will update automatically on new commits. Configure here.

@meiravgri meiravgri requested a review from JoanFM November 26, 2025 18:15
@meiravgri meiravgri changed the title Meiravg_active_threads [MOD-12694] [MOD-12069] Add active_worker_threads metric Nov 26, 2025

typedef struct {
size_t active_io_threads; // number of I/O thread callbacks currently executing
size_t active_coord_threads; // number of coordinator thread callbacks currently executing (reserved for future use)
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove the coord_threads and add them in another PR?

args=(runDebugQueryCommandPauseBeforeRPAfterN,
(env, [query_type, 'idx', '*'], 'Index', 0, ['INTERNAL_ONLY']),
result_list),
daemon=True
Copy link
Collaborator

Choose a reason for hiding this comment

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

just comment, if we are joining, do not need to add daemon true

JoanFM
JoanFM previously approved these changes Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.69%. Comparing base (9ccdf3e) to head (399bb53).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7538      +/-   ##
==========================================
- Coverage   84.69%   84.69%   -0.01%     
==========================================
  Files         349      349              
  Lines       53923    53928       +5     
  Branches    14485    14485              
==========================================
+ Hits        45671    45674       +3     
- Misses       8063     8065       +2     
  Partials      189      189              
Flag Coverage Δ
flow 85.03% <100.00%> (-0.13%) ⬇️
unit 52.04% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

MultiThreadingStats GlobalStats_GetMultiThreadingStats() {
MultiThreadingStats stats;
stats.active_io_threads = READ(RSGlobalStats.totalStats.multi_threading.active_io_threads);
stats.active_worker_threads = workersThreadPool_WorkingThreadCount();
Copy link

Choose a reason for hiding this comment

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

Bug: NULL pointer dereference when worker pool uninitialized

The new call to workersThreadPool_WorkingThreadCount() in GlobalStats_GetMultiThreadingStats() can crash when the worker thread pool hasn't been initialized. The function workersThreadPool_WorkingThreadCount() only has a debug assertion (RS_ASSERT) for the null check, which is stripped in release builds. When _workers_thpool is NULL, calling redisearch_thpool_num_jobs_in_progress(_workers_thpool) will dereference a null pointer. This breaks existing tests like ActiveIoThreadsMetric in test_cpp_io_runtime_ctx.cpp that call GlobalStats_GetMultiThreadingStats() without initializing the worker pool. Other similar functions like workersThreadPool_getStats() properly return a default value when the pool is NULL.

Fix in Cursor Fix in Web

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thank you !

Copy link
Collaborator Author

@meiravgri meiravgri Nov 27, 2025

Choose a reason for hiding this comment

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

i decided not to call workersThreadPool_getStats because intenally it locks the thpool, which i like to avoid

Base automatically changed from meiravg_uv_active_thread_counter to master November 27, 2025 10:10
@meiravgri meiravgri dismissed JoanFM’s stale review November 27, 2025 10:10

The base branch was changed.

@meiravgri meiravgri force-pushed the meiravg_active_threads branch from 161317e to be74191 Compare November 27, 2025 12:16
@meiravgri meiravgri requested a review from JoanFM November 27, 2025 12:17
@meiravgri meiravgri enabled auto-merge November 27, 2025 12:18
MultiThreadingStats GlobalStats_GetMultiThreadingStats() {
MultiThreadingStats stats;
stats.active_io_threads = READ(RSGlobalStats.totalStats.multi_threading.active_io_threads);
RS_ASSERT(workersThreadPool_isInitialized()); // In production workers threadpool is initialized at startup.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not really true I believe. The ThreadPool is initialized lazily when some queries have been scheduled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, it differs from the state. We should call it differently

}

bool workersThreadPool_isInitialized() {
return _workers_thpool != NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's choice another naming to avoid the confusion with the thpool->state (UNITIALIZED, etc ...)

JoanFM
JoanFM previously approved these changes Nov 27, 2025
@meiravgri meiravgri added this pull request to the merge queue Nov 27, 2025
Removed skip decorator from test_active_io_threads_stats.
@meiravgri meiravgri requested a review from JoanFM November 27, 2025 18:08
Copy link
Collaborator

@JoanFM JoanFM left a comment

Choose a reason for hiding this comment

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

I would perhaps opt to do the assert inside the workers API

@meiravgri meiravgri added this pull request to the merge queue Nov 27, 2025
Merged via the queue into master with commit d9574d8 Nov 27, 2025
26 checks passed
@meiravgri meiravgri deleted the meiravg_active_threads branch November 27, 2025 22:21
@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.8
git worktree add -d .worktree/backport-7538-to-2.8 origin/2.8
cd .worktree/backport-7538-to-2.8
git switch --create backport-7538-to-2.8
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.10, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.10
git worktree add -d .worktree/backport-7538-to-2.10 origin/2.10
cd .worktree/backport-7538-to-2.10
git switch --create backport-7538-to-2.10
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Nov 27, 2025
* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)
@redisearch-backport-pull-request
Copy link
Contributor

Successfully created backport PR for 8.2:

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 8.4, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 8.4
git worktree add -d .worktree/backport-7538-to-8.4 origin/8.4
cd .worktree/backport-7538-to-8.4
git switch --create backport-7538-to-8.4
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

github-merge-queue bot pushed a commit that referenced this pull request Dec 1, 2025
* [MOD-12694] [MOD-12069] Add active_worker_threads metric (#7538)

* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)

* import threading

* take common from master

* fix merge

* revert change

* add threading

---------

Co-authored-by: meiravgri <[email protected]>
Co-authored-by: meiravgri <[email protected]>
meiravgri added a commit that referenced this pull request Dec 2, 2025
* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)
@meiravgri
Copy link
Collaborator Author

/backport

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.8
git worktree add -d .worktree/backport-7538-to-2.8 origin/2.8
cd .worktree/backport-7538-to-2.8
git switch --create backport-7538-to-2.8
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.10, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.10
git worktree add -d .worktree/backport-7538-to-2.10 origin/2.10
cd .worktree/backport-7538-to-2.10
git switch --create backport-7538-to-2.10
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 8.2, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 8.2
git worktree add -d .worktree/backport-7538-to-8.2 origin/8.2
cd .worktree/backport-7538-to-8.2
git switch --create backport-7538-to-8.2
git cherry-pick -x d9574d8b0de0a9ead43c0de696686c187e410173

github-merge-queue bot pushed a commit that referenced this pull request Dec 2, 2025
* [MOD-12694] [MOD-12069] Add active_worker_threads metric (#7538)

* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)

* Merge branch '8.4' into backport-7538-to-8.4

* Revert "Merge branch '8.4' into backport-7538-to-8.4"

This reverts commit 493db61.
meiravgri added a commit that referenced this pull request Dec 4, 2025
github-merge-queue bot pushed a commit that referenced this pull request Dec 8, 2025
* [MOD-12694] [MOD-12069] Add active_worker_threads metric (#7538)

WIP: needs #7579 backport

* wrapp reading from workers only if mt_build

fix test

* fix test

* review
meiravgri added a commit that referenced this pull request Dec 9, 2025
* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)
github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2025
* [MOD-12694] [MOD-12069] Add active_worker_threads metric (#7538)

* add "active_worker_threads" metric

* fix declartion

* remove coord threads

* make the tests run...

* introduce workersThreadPool_isInitialized
assert is initizlied in GlobalStats_GetMultiThreadingStats

* cleanup

* rename workersThreadPool_isCreated

* Unskip test_active_io_threads_stats

Removed skip decorator from test_active_io_threads_stats.

(cherry picked from commit d9574d8)

* add deps in common.py

* remove call_and_store

* fix io test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants