@@ -267,6 +267,7 @@ public List<AutoScalingUtilizationMetric> executorUtilizations() { |
267 | 267 |
|
268 | 268 | private final class UtilizationMonitor implements Runnable { |
269 | 269 | private final List<SingleThreadEventExecutor> consistentlyIdleChildren = new ArrayList<>(maxChildren); |
| 270 | + private final List<SingleThreadEventExecutor> consistentlyBusyChildren = new ArrayList<>(maxChildren); |
270 | 271 | private long lastCheckTimeNanos; |
271 | 272 |
|
272 | 273 | @Override |
@@ -297,8 +298,8 @@ public void run() { |
297 | 298 | return; |
298 | 299 | } |
299 | 300 |
|
300 | | - int consistentlyBusyChildren = 0; |
301 | 301 | consistentlyIdleChildren.clear(); |
| 302 | + consistentlyBusyChildren.clear(); |
302 | 303 |
|
303 | 304 | final AutoScalingState currentState = state.get(); |
304 | 305 |
|
@@ -341,7 +342,7 @@ public void run() { |
341 | 342 | int busyCycles = eventExecutor.getAndIncrementBusyCycles(); |
342 | 343 | eventExecutor.resetIdleCycles(); |
343 | 344 | if (busyCycles >= scalingPatienceCycles) { |
344 | | - consistentlyBusyChildren++; |
| 345 | + consistentlyBusyChildren.add(eventExecutor); |
345 | 346 | } |
346 | 347 | } else { |
347 | 348 | // Utilization is in the normal range, reset counters. |
@@ -356,11 +357,17 @@ public void run() { |
356 | 357 | int currentActive = currentState.activeChildrenCount; |
357 | 358 |
|
358 | 359 | // Make scaling decisions based on stable states. |
359 | | - if (consistentlyBusyChildren > 0 && currentActive < maxChildren) { |
| 360 | + if (!consistentlyBusyChildren.isEmpty() && currentActive < maxChildren) { |
360 | 361 | // Scale Up, we have children that have been busy for multiple cycles. |
361 | | - int threadsToAdd = Math.min(consistentlyBusyChildren, maxRampUpStep); |
| 362 | + int threadsToAdd = Math.min(consistentlyBusyChildren.size(), maxRampUpStep); |
362 | 363 | threadsToAdd = Math.min(threadsToAdd, maxChildren - currentActive); |
363 | 364 | if (threadsToAdd > 0) { |
| 365 | + // Reset the counters of the children that justified this decision so that they need |
| 366 | + // another full patience period of sustained load before triggering a further scale-up. |
| 367 | + for (SingleThreadEventExecutor busyChild : consistentlyBusyChildren) { |
| 368 | + busyChild.resetBusyCycles(); |
| 369 | + busyChild.resetIdleCycles(); |
| 370 | + } |
364 | 371 | tryScaleUpBy(threadsToAdd); |
365 | 372 | // State change is handled by tryScaleUpBy, no need for rebuild here. |
366 | 373 | return; // Exit to avoid conflicting scale down logic in the same cycle. |
|