mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(docker): make the Docker client pool size configurable, default 1024 (#4276)
The shared DockerClient's connection pool was hard-coded to 100. Each live Lambda container holds two of those connections for its whole lifetime (the followed log stream and the exit watcher), so about 50 warm containers exhaust the pool. Create, start, stop and remove then wait for a free connection, including the idle-container stop that would release one, and the emulator stalls. Expose the size as floci.docker.max-connections (FLOCI_DOCKER_MAX_CONNECTIONS), reject values below 1, and default it to 1024 so that the 500-port Lambda runtime API range, not the Docker pool, is the ceiling on concurrent Lambda containers. Refs #2219, #2224 Co-authored-by: Goooooooooody <205637002+Goooooooooody@users.noreply.github.com>
This commit is contained in:
1 parent
8c2ceb5aa1
commit
76f8c09341
9 files changed
+163
-3
No files matched your search
@@ -3324,6 +3324,22 @@ public interface EmulatorConfig {
|
||||
@WithDefault("unix:///var/run/docker.sock")
|
||||
String dockerHost();
|
||||
|
||||
/**
|
||||
* Size of the connection pool behind the shared Docker client. Every Docker call leases a
|
||||
* connection from it, and some hold one for as long as a container runs: a Lambda
|
||||
* container holds two (its followed log stream and its exit watcher) plus one per
|
||||
* extension, and other container-backed services hold one for their log stream. Once
|
||||
* those fill the pool, create, start, stop and remove wait for a free connection,
|
||||
* including the calls that would release one, so the emulator stalls.
|
||||
*
|
||||
* <p>1024 rather than the former hard-coded 100, which capped live Lambda containers at
|
||||
* about 50: a tenth of the 500 that the runtime API port range
|
||||
* ({@link LambdaServiceConfig#runtimeApiBasePort}) exists to allow. Connections are
|
||||
* opened on demand, so a small stack never approaches the limit.
|
||||
*/
|
||||
@WithDefault("1024")
|
||||
int maxConnections();
|
||||
|
||||
/**
|
||||
* Optional namespace inserted into Floci-managed child container and volume names.
|
||||
* Useful when multiple Floci processes share one Docker daemon.
|
||||
|
||||
+15
-2
@@ -396,12 +396,25 @@ public class DockerClientProducer {
|
||||
return System.getProperty("os.name", "").toLowerCase().contains("win");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects a pool size below 1 with a message naming the setting, instead of leaving the
|
||||
* connection pool to reject it with a generic error.
|
||||
*/
|
||||
static int validateMaxConnections(int maxConnections) {
|
||||
if (maxConnections < 1) {
|
||||
throw new IllegalArgumentException("floci.docker.max-connections (FLOCI_DOCKER_MAX_CONNECTIONS) "
|
||||
+ "must be at least 1, got: " + maxConnections);
|
||||
}
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
@Produces
|
||||
@ApplicationScoped
|
||||
public DockerClient dockerClient() {
|
||||
int maxConnections = validateMaxConnections(config.docker().maxConnections());
|
||||
ResolvedDockerConnection connection = resolveDockerConnection(config.docker(), System::getenv);
|
||||
String dockerHost = connection.host();
|
||||
LOG.infov("Creating DockerClient for host: {0}", dockerHost);
|
||||
LOG.infov("Creating DockerClient for host: {0} (max connections: {1})", dockerHost, maxConnections);
|
||||
|
||||
// createDefaultConfigBuilder() reads DOCKER_HOST directly from System.getenv() and passes
|
||||
// it to withDockerHost(), which calls URI.create() immediately. If DOCKER_HOST is set
|
||||
@@ -430,7 +443,7 @@ public class DockerClientProducer {
|
||||
|
||||
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
|
||||
.dockerHost(clientConfig.getDockerHost())
|
||||
.maxConnections(100)
|
||||
.maxConnections(maxConnections)
|
||||
.connectionTimeout(Duration.ofSeconds(30))
|
||||
.responseTimeout(Duration.ofMinutes(5))
|
||||
.build();
|
||||
|
||||
Reference in new issue
Block a user