Skip to content

Commit

Permalink
WIP: Experimental change to benchmark TLS overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Dec 17, 2024
1 parent 207978e commit 088b695
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/src/main/java/org/polypheny/db/docker/DockerContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -243,13 +250,39 @@ 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() );
}
}


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
*/
Expand Down

0 comments on commit 088b695

Please sign in to comment.