[MOD-12694] [MOD-12069] Add active_worker_threads metric#7538
[MOD-12694] [MOD-12069] Add active_worker_threads metric#7538
Conversation
src/info/global_stats.h
Outdated
|
|
||
| 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
just comment, if we are joining, do not need to add daemon true
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| MultiThreadingStats GlobalStats_GetMultiThreadingStats() { | ||
| MultiThreadingStats stats; | ||
| stats.active_io_threads = READ(RSGlobalStats.totalStats.multi_threading.active_io_threads); | ||
| stats.active_worker_threads = workersThreadPool_WorkingThreadCount(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
i decided not to call workersThreadPool_getStats because intenally it locks the thpool, which i like to avoid
assert is initizlied in GlobalStats_GetMultiThreadingStats
161317e to
be74191
Compare
src/info/global_stats.c
Outdated
| 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. |
There was a problem hiding this comment.
This is not really true I believe. The ThreadPool is initialized lazily when some queries have been scheduled.
There was a problem hiding this comment.
Ah I see, it differs from the state. We should call it differently
| } | ||
|
|
||
| bool workersThreadPool_isInitialized() { | ||
| return _workers_thpool != NULL; |
There was a problem hiding this comment.
Let's choice another naming to avoid the confusion with the thpool->state (UNITIALIZED, etc ...)
Removed skip decorator from test_active_io_threads_stats.
JoanFM
left a comment
There was a problem hiding this comment.
I would perhaps opt to do the assert inside the workers API
|
Backport failed for 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 |
|
Backport failed for 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 |
* 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)
|
Successfully created backport PR for |
|
Backport failed for 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 |
* [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]>
* 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)
|
/backport |
|
Backport failed for 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 |
|
Backport failed for 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 |
|
Backport failed for 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 |
* [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.
* 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)
* [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
Extends the
multi_threadingsection inINFO MODULESby addingsearch_active_worker_threadsmetric to track currently executing worker thread queries.Continues #7530 which added
search_multi_threadingsection andsearch_active_io_threadsfield.INFO MODULES Output
Note
Expose current worker thread activity via
search_active_worker_threadsinINFO MODULESalongside existing I/O stats.multi_threadingwithactive_worker_threadsinsrc/info/info_redis/info_redis.cusingGlobalStats_GetMultiThreadingStats().active_worker_threadstoMultiThreadingStats(src/info/global_stats.h).workersThreadPool_WorkingThreadCount()with safety assertworkersThreadPool_isCreated()(src/info/global_stats.c).workersThreadPool_isCreated()API (src/util/workers.{h,c}).search_multi_threading.search_active_worker_threadsbehavior 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.