Repository navigation
Changes for Auto Scaling Netty threads - #15797
isaacrivriv wants to merge 5 commits into
Conversation
|
Will wait once ready, and will take a look :) |
|
At a first look (I have still to debug it) the paused executor set shouldn't be passed from the old to the new state as it is but need to be re-created new, without modifying the old one which could be a accessed concurrently by others which try to update the state |
|
Yeah as I was working on this I was thinking about that too and wondering what could happen. From my understanding, the only other code that could clash with the @Override
public EventExecutor next() {
// Get a snapshot of the current state.
AutoScalingState currentState = this.state.get();
if (currentState.activeExecutors.length == 0) {
// This is only reachable if minChildren is 0 and the monitor has just suspended the last active thread.
// To prevent an error and ensure the group can recover, we wake one up and use the
// chooser that contains all executors as a safe temporary choice.
tryScaleUpBy(1);
return allExecutorsChooser.next();
}
return currentState.activeExecutorsChooser.next();
}Before the changes given that the state could be modified from another thread, I thought race conditions could occur but I noticed the "infinite" for loop in the |
|
I just added a test to verify that idle executors with registered channels should not be suspended while also not be reported as active executors. This should now be ready for review |
in theory for each (successfull) state change. you can still reuse the newly allocated Re been the "right thing to do" IDK yet; is single threaded, for example (IIRC) |
|
While testing with minChildren = 0 I ran into some weird behavior when attempting to scale down after scaling up from 0 where no attempt to scale down was done even without the changes to pause the active executors. I opened #15809 to discuss |
|
Ping to see if we can get this reviewed/merged in... not sure if we would like #15813 as a prereq before merging these changes |
|
ping @georgebanasios |
|
lgtm |
2d0fc40 to
d8982d3
Compare
- Added changes for pausing executors that are idle to finish up active connections before being suspended
Co-authored-by: Norman Maurer <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
d8982d3 to
581e494
Compare
|
@normanmaurer @franz1981 should be ready for review/merge when you get a chance |
|
I found two concurrency problems in how What goes wrong in the current code
1. } else if (oldState.pausedExecutors.remove(stee)) { // mutates the shared set
wokenUp.add(stee);
}
...
if (state.compareAndSet(oldState, newState)) { return; }
// CAS failed -> loop againIf the CAS fails, the removal has already happened. On the retry the executor is neither suspended nor paused, so it is skipped. It is not in any This needs two threads. The monitor can't race itself ( 2. tryScaleUpBy(1);
EventExecutor executor = allExecutorsChooser.next(); // not necessarily the executor that was woken
this.state.get().pausedExecutors.remove(executor); // outside any CAS
Fix
Test
Diff against the PR head (
|
- Ensure AutoScalingState remains strictly immutable by never mutating pausedExecutors in place. - Produce a new set published via CAS to prevent losing executors during concurrent scale-up or rebuilds.
✅ All tests passed ✅🏷️ Commit: bb3587a Learn more about TestLens at testlens.app/docs. |
|
@normanmaurer @franz1981 gentle review reminder to see if we can get this merged in |
|
Any chance we can follow up again on this PR to get it merged? Sorry for the continued pings @normanmaurer @franz1981 Same for |
|
PTAL @normanmaurer ? to me it looks good |
|
@isaacrivriv I think there is still one issue... what do you think of this fix: If you agree feel free to apply and push |
|
@isaacrivriv ping |
Changes
Motivation:
Idle executors still handling connections are not properly suspended and would remain active even if under the down scale threshold for as long as at least one connection remains active.
Modification:
Added a set of paused executors to the AutoScaling state and appropriate logic to manage idle executors which are still handling connections. Also updated pom.xml for issues compiling changes due to revapi
Result:
Fixes #15777