Skip to content

Commit

Permalink
Improved Docker Restart Time Between Benchmarks (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanbrub authored Jul 13, 2023
1 parent 79e1eab commit bad215d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ String listStr(String... values) {

void restartDocker(Bench api) {
var dockerComposeFile = api.property("docker.compose.file", "");
Exec.restartDocker(dockerComposeFile);
var deephavenHostPort = api.property("deephaven.addr", "");
Exec.restartDocker(dockerComposeFile, deephavenHostPort);
}

void generateQuotesTable(long rowCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void runTest(String testName, String tableName, long baseRowCount, long rowCount

void restartDocker(Bench api) {
var timer = api.timer();
if (!Exec.restartDocker(api.property("docker.compose.file", "")))
if (!Exec.restartDocker(api.property("docker.compose.file", ""), api.property("deephaven.addr", "")))
return;
var metrics = new Metrics(Timer.now(), "test-runner", "setup", "docker");
metrics.set("restart", timer.duration().toMillis(), "standard");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Bench initialize(Object testInst) {

void restartDocker(Bench api) {
var timer = api.timer();
if (!Exec.restartDocker(api.property("docker.compose.file", "")))
if (!Exec.restartDocker(api.property("docker.compose.file", ""), api.property("deephaven.addr", "")))
return;
var metrics = new Metrics(Timer.now(), "test-runner", "setup", "docker");
metrics.set("restart", timer.duration().toMillis(), "standard");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ private String getResultTableSize(String operation) {

private void restartDocker(Bench api, int heapGigs) {
String dockerComposeFile = api.property("docker.compose.file", "");
if (dockerComposeFile.isBlank())
String deephavenHostPort = api.property("deephaven.addr", "");
if (dockerComposeFile.isBlank() || deephavenHostPort.isBlank())
return;
dockerComposeFile = makeHeapAdjustedDockerCompose(dockerComposeFile, heapGigs);
var timer = api.timer();
Exec.restartDocker(dockerComposeFile);
Exec.restartDocker(dockerComposeFile, deephavenHostPort);
var metrics = new Metrics(Timer.now(), "test-runner", "setup", "docker");
metrics.set("restart", timer.duration().toMillis(), "standard");
api.metrics().add(metrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Bench initialize(Object testInst) {

void restartDocker(Bench api) {
var timer = api.timer();
if (!Exec.restartDocker(api.property("docker.compose.file", "")))
if (!Exec.restartDocker(api.property("docker.compose.file", ""), api.property("deephaven.addr", "")))
return;
var metrics = new Metrics(Timer.now(), "test-runner", "setup", "docker");
metrics.set("restart", timer.duration().toMillis(), "standard");
Expand Down
48 changes: 33 additions & 15 deletions src/main/java/io/deephaven/benchmark/util/Exec.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.util;

import java.io.*;
import java.net.*;
import java.util.concurrent.TimeUnit;

/**
* Utils for executing processes from the command line.
* </p>
* Note: No effort has been made to make this secure or prevent any horror.ss
* Note: No effort has been made to make this secure
*/
public class Exec {
/**
* Restart a docker container using <code>docker compose</code>. If the given compose file is blank skip.
* Restart a docker container using <code>docker compose</code>. If the given compose file property is blank skip.
*
* @param dockerComposeFile the path to the relevant docker-compose.yml
* @param deephavenHostPort the host:port of the Deephaven service
* @return true if attempted docker restart, otherwise false
*/
static public boolean restartDocker(String dockerComposeFile) {
if (dockerComposeFile.isBlank())
static public boolean restartDocker(String dockerComposeFile, String deephavenHostPort) {
if (dockerComposeFile.isBlank() || deephavenHostPort.isBlank())
return false;
exec("sudo docker compose -f " + dockerComposeFile + " down");
Threads.sleep(1000);
exec("sudo docker compose -f " + dockerComposeFile + " down --timeout 0");
exec("sudo docker compose -f " + dockerComposeFile + " up -d");
Threads.sleep(3000);
return true;
long beginTime = System.currentTimeMillis();
while (System.currentTimeMillis() - beginTime < 10000) {
var status = getUrlStatus("http://" + deephavenHostPort + "/ide/");
if (status)
return true;
Threads.sleep(100);
}
return false;
}

/**
Expand All @@ -46,12 +52,24 @@ static public int exec(String command) {
}
}

static String copyToString(InputStream input) throws Exception {
var out = new StringWriter();
try (InputStream in = input) {
for (int i = 0; i < in.available(); i++)
out.write(in.read());
return out.toString();
static boolean getUrlStatus(String uri) {
var url = createUrl(uri);
try {
var connect = url.openConnection();
if (!(connect instanceof HttpURLConnection))
return false;
var code = ((HttpURLConnection) connect).getResponseCode();
return (code == 200);
} catch (Exception ex) {
return false;
}
}

static URL createUrl(String uri) {
try {
return new URL(uri);
} catch (MalformedURLException e) {
throw new RuntimeException("Bad URL: " + uri);
}
}

Expand Down

0 comments on commit bad215d

Please sign in to comment.