From 088b695069f5071097dc74ccd796d364d3264949 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 27 Nov 2024 18:34:31 +0100 Subject: [PATCH] WIP: Experimental change to benchmark TLS overhead --- .../polypheny/db/docker/DockerContainer.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/src/main/java/org/polypheny/db/docker/DockerContainer.java b/core/src/main/java/org/polypheny/db/docker/DockerContainer.java index bd0f43c745..77b9ad0282 100644 --- a/core/src/main/java/org/polypheny/db/docker/DockerContainer.java +++ b/core/src/main/java/org/polypheny/db/docker/DockerContainer.java @@ -16,6 +16,12 @@ package org.polypheny.db.docker; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.InspectContainerResponse; +import com.github.dockerjava.core.DefaultDockerClientConfig; +import com.github.dockerjava.core.DockerClientConfig; +import com.github.dockerjava.core.DockerClientImpl; +import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -26,6 +32,7 @@ import java.net.SocketException; import java.net.StandardSocketOptions; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -243,6 +250,11 @@ private ServerSocket startServer( int port ) { public HostAndPort connectToContainer( int port ) { + if ( Catalog.mode == RunMode.BENCHMARK ) { + log.warn( "Using direct Docker connection in benchmark mode" ); + return connectToContainerDirectly( 5432 ); + } + synchronized ( this ) { ServerSocket s = proxies.computeIfAbsent( port, this::startServer ); return new HostAndPort( s.getInetAddress().getHostAddress(), s.getLocalPort() ); @@ -250,6 +262,27 @@ public HostAndPort connectToContainer( int port ) { } + public HostAndPort connectToContainerDirectly( int port ) { + DockerClientConfig config = DefaultDockerClientConfig + .createDefaultConfigBuilder() + .build(); + + ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder() + .dockerHost( config.getDockerHost() ) + .sslConfig( config.getSSLConfig() ) + .responseTimeout( Duration.ofSeconds( RuntimeConfig.DOCKER_TIMEOUT.getInteger() ) ) + .connectionTimeout( Duration.ofSeconds( RuntimeConfig.DOCKER_TIMEOUT.getInteger() ) ) + .build(); + + DockerClient client = DockerClientImpl.getInstance( config, httpClient ); + + InspectContainerResponse resp = client.inspectContainerCmd( this.containerId ).exec(); + + String ip = resp.getNetworkSettings().getNetworks().get( "polypheny-internal" ).getIpAddress(); + return new HostAndPort( ip, port ); + } + + /** * The container gets probed until the defined ready supplier returns true or the timeout is reached */