Operations 12 min read

Improving REPL Container Shutdown Performance at Replit

Replit engineers analyzed why container shutdown on preemptible VMs caused REPL sessions to stall for up to a minute, identified Docker's network‑release bottleneck, and implemented a direct SIGKILL workaround that reduced error rates and startup latency dramatically.

Top Architect
Top Architect
Top Architect
Improving REPL Container Shutdown Performance at Replit

Replit, a browser‑based IDE, runs user code on preemptible virtual machines; when a VM is terminated the REPL connection can stall for up to a minute because Docker containers are killed slowly.

The engineering team investigated the shutdown path, discovered that killing 200 containers took about 38 seconds, and identified that most of the delay was spent releasing network resources via netlink and waiting on container locks.

By adding detailed logging they pinpointed the bottleneck in the container manager (conman) and the Docker engine’s container.Wait and network address release steps.

To bypass the delay they implemented a direct SIGKILL to the container’s PID, avoiding Docker’s cleanup and freeing the REPL within seconds, reducing error rates from ~3 % to <0.5 % and 99th‑percentile startup time from 2 minutes to 15 seconds.

The article also includes a Bash script that launches 200 Docker containers and measures the time required to kill them, as well as sample Docker daemon debug logs illustrating the long‑running operations.

#!/bin/bash
COUNT=200
echo "Starting $COUNT containers..."
for i in $(seq 1 $COUNT); do
  printf .
  docker run -d --name test-$i nginx > /dev/null 2>&1
done
echo -e "\nKilling $COUNT containers..."
time $(docker kill $(docker container ls -a --filter "name=test" --format "{{.ID}}" ) > /dev/null 2>&1)
echo -e "\nCleaning up..."
docker rm $(docker container ls -a --filter "name=test" --format "{{.ID}}" ) > /dev/null 2>&1
Dockerperformance optimizationOpsContainer ManagementBackend InfrastructureReplit
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.