Skip to content

[8.4] [MOD-12252] [MOD-11658] reduce number of worker threads asynchronously#7519

Merged
JoanFM merged 2 commits into8.4from
backport-7410-to-8.4
Nov 26, 2025
Merged

[8.4] [MOD-12252] [MOD-11658] reduce number of worker threads asynchronously#7519
JoanFM merged 2 commits into8.4from
backport-7410-to-8.4

Conversation

@JoanFM
Copy link
Collaborator

@JoanFM JoanFM commented Nov 26, 2025

Backport of #7410


Note

Make worker thread reduction asynchronous via new thpool API and update workers management/tests accordingly.

  • Threadpool (deps/thpool):
    • Add async thread-reduction API redisearch_thpool_schedule_config_reduce_threads_job(...) using ADMIN jobs + barrier; remove blocking remove_threads and terminate_when_empty APIs.
    • Make thread_do take arg struct; signal startup via started flags for deterministic init waits; update thread_init/add_threads to wait on per-thread start.
    • Factor job push helpers (redisearch_thpool_push_chain, _add_n_work_not_verify_init) and use RS_ASSERT; minor log/strings tweaks.
    • Maintain UNINITIALIZED state on terminate-when-empty path; keep terminate_threads and stats intact.
  • Workers management (src/util/workers.c):
    • Switch resizing logic to new async reducer (both remove-some and remove-all-when-empty); keep adds synchronous; extra logging and assertions.
  • Debug/Config:
    • FT.DEBUG WORKERS DRAIN warning about possible deadlock; comments updated in config setters.
  • Tests:
    • Update C++ thpool tests to new async API and startup signaling.
    • Add/extend Python tests for worker scaling, zero↔nonzero transitions, gradual reductions, and responsiveness under load (MOD-11658).

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

#7410)

* change number of threads asynchronously

* do some changes to add thread

* improve code

* cancel old config change if happens

* more improvements

* destroy when sure noone needsit

* simplify implementation drastically

* improve async implementation

* revert barrier changes

* test: do not skip on standalone

* test: add new test

* fix tests

* remove extra tests

* remove unneeded code

* delay ensure init after

* fix: remove weird unlock

* test: handle cpp tests

* small improvement on the test

* improve the checking of thread starting

* remove some unneeded functions from thpool

* remove unused code from tests

* small cleanup of code

* update deps/thpool/thpool.c

* add checks to thpool stats in test

* fix multithread test

* fix memory leak and remove unreachable code

* assert some invariants

* fix: respect adding workers is a lazy operation even after start

* small changes

* remove double assertion

* add another assertion

* small change to avoid dangling pointer in stack

* changes according to comments to the code

* change tests of place and simplify some

* small change

* try to improve flakiness and test time using TimeLimit

* make static and reuse code

* Update deps/thpool/thpool.c

Co-authored-by: GuyAv46 <[email protected]>

* add volatile to started array

* remove extra assertion

* add warning to ft debug command code comment

* change assertion method

* remove flakiness from test

* change test query while flush test

* Update deps/thpool/thpool.c

Co-authored-by: GuyAv46 <[email protected]>

* Update deps/thpool/thpool.c

Co-authored-by: GuyAv46 <[email protected]>

---------

Co-authored-by: GuyAv46 <[email protected]>
(cherry picked from commit 874ce68)
@JoanFM JoanFM changed the title [MOD-12252] [MOD-11658] reduce number of worker threads asynchronousl… [MOD-12252] [MOD-11658] reduce number of worker threads asynchronously Nov 26, 2025
@JoanFM JoanFM changed the title [MOD-12252] [MOD-11658] reduce number of worker threads asynchronously [8.4] [MOD-12252] [MOD-11658] reduce number of worker threads asynchronously Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 97.02970% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (8145155) to head (dc0ae23).
⚠️ Report is 3 commits behind head on 8.4.

Files with missing lines Patch % Lines
deps/thpool/thpool.c 96.80% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              8.4    #7519      +/-   ##
==========================================
- Coverage   85.87%   85.84%   -0.03%     
==========================================
  Files         330      330              
  Lines       52465    52520      +55     
  Branches    12001    12001              
==========================================
+ Hits        45055    45087      +32     
- Misses       7243     7266      +23     
  Partials      167      167              
Flag Coverage Δ
flow 84.40% <95.04%> (-0.29%) ⬇️
unit 52.47% <87.12%> (-0.02%) ⬇️

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.

@JoanFM JoanFM enabled auto-merge November 26, 2025 13:04
@JoanFM JoanFM requested review from GuyAv46 and alonre24 November 26, 2025 13:04
@JoanFM JoanFM added this pull request to the merge queue Nov 26, 2025
Merged via the queue into 8.4 with commit 91ea955 Nov 26, 2025
26 checks passed
@JoanFM JoanFM deleted the backport-7410-to-8.4 branch November 26, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants