fix(lambda): drain warm containers across functions concurrently (#5899)

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-18 21:14:29 -04:00
1 parent 94288dadd9
commit 9ceedde585
2 files changed
+59 -5

No files matched your search

@@ -367,6 +367,10 @@ public class WarmPool implements ContainerTeardown {
* Called on function deletion and emulator shutdown.
*/
public void drainFunction(String functionName) {
stopInParallel(detachFunction(functionName));
}
private List<ContainerHandle> detachFunction(String functionName) {
PoolState poolState = poolStates.computeIfAbsent(functionName, ignored -> new PoolState());
List<ContainerHandle> toStop;
synchronized (poolState) {
@@ -376,16 +380,15 @@ public class WarmPool implements ContainerTeardown {
poolState.idleByEnvironment.clear();
}
LOG.infov("Draining {0} container(s) for function: {1}", toStop.size(), functionName);
stopInParallel(toStop);
return toStop;
}
private void stopInParallel(List<ContainerHandle> handles) {
if (handles.isEmpty()) {
return;
}
int parallelism = Math.min(handles.size(), 16);
ExecutorService pool = Executors.newFixedThreadPool(parallelism,
r -> { Thread t = new Thread(r, "warm-pool-drainer"); t.setDaemon(true); return t; });
ExecutorService pool = Executors.newThreadPerTaskExecutor(
Thread.ofVirtual().name("warm-pool-drainer-", 0).factory());
try {
List<Future<?>> futures = new ArrayList<>(handles.size());
for (ContainerHandle handle : handles) {
@@ -404,9 +407,11 @@ public class WarmPool implements ContainerTeardown {
}
private void drainAll() {
List<ContainerHandle> toStop = new ArrayList<>();
for (String functionName : new ArrayList<>(poolStates.keySet())) {
drainFunction(functionName);
toStop.addAll(detachFunction(functionName));
}
stopInParallel(toStop);
}
private void evictIdleContainers() {