From 77ad873b79df97014349afe43662f1656c589961 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 28 Feb 2018 12:05:17 +0100 Subject: [PATCH 1/2] fix usage of the datasources example The `datasources-subsystem` example no longer exists. Instead, the `datasources-war` example is used. That example, however, needs to be started in one of 3 profiles; the default profile doesn't include any datasource and so the example doesn't work. To be able to do this, this commit adds the ability to specify arguments to the `java -jar *-swarm.jar` commands in a special file called `swarm-app-args.properties`. --- .../java/org/wildfly/swarm/proc/Monitor.java | 28 +++++++++++++++---- src/main/resources/swarm-app-args.properties | 1 + src/main/resources/swarm-apps.properties | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/swarm-app-args.properties diff --git a/src/main/java/org/wildfly/swarm/proc/Monitor.java b/src/main/java/org/wildfly/swarm/proc/Monitor.java index a046be8..e87645f 100644 --- a/src/main/java/org/wildfly/swarm/proc/Monitor.java +++ b/src/main/java/org/wildfly/swarm/proc/Monitor.java @@ -25,6 +25,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -180,10 +183,14 @@ private void run() throws Exception { Properties props = new Properties(); props.load(Monitor.class.getClassLoader().getResourceAsStream("swarm-apps.properties")); + Properties argsProps = new Properties(); + argsProps.load(Monitor.class.getClassLoader().getResourceAsStream("swarm-app-args.properties")); + // first phase: main test execution loop for (Object o : props.keySet()) { String swarmFile = (String) o; String httpCheck = (String) props.get(o); + String swarmArgs = (String) argsProps.get(o); File file = new File(this.baseDir, swarmFile); String id = file.getAbsolutePath(); @@ -191,9 +198,13 @@ private void run() throws Exception { if (!file.exists()) throw new RuntimeException("File does not exist: " + file.getAbsolutePath()); + List argsList = swarmArgs == null + ? Collections.emptyList() + : Arrays.asList(swarmArgs.split("\\s+")); + collector.onBegin(id); for (int i = 0; i < NUM_ITERATIONS; i++) { - runTest(i, file, httpCheck, collector); + runTest(i, file, httpCheck, argsList, collector); } collector.onFinish(id); } @@ -269,9 +280,10 @@ private Optional getPreviousResults(Path currentOutput, File dir * @param iteration * @param file * @param httpCheck + * @param processArgs * @param collector */ - private void runTest(int iteration, File file, String httpCheck, final Collector collector) { + private void runTest(int iteration, File file, String httpCheck, List processArgs, final Collector collector) { System.out.println("Testing " + file.getAbsolutePath() + ", iteration " + iteration); String id = file.getAbsolutePath(); @@ -284,10 +296,14 @@ private void runTest(int iteration, File file, String httpCheck, final Collector Path workDir = Files.createDirectories(this.workDir.toPath().resolve(Paths.get(file.getName(), "iteration-" + iteration))); Path tmp = Files.createDirectory(workDir.resolve("tmp")); - ProcessBuilder pb = new ProcessBuilder("java", - "-Duid=" + uid, - "-Djava.io.tmpdir=" + tmp.toAbsolutePath().toString(), - "-jar", file.getAbsolutePath()) + List command = new ArrayList<>(); + command.addAll(Arrays.asList("java", + "-Duid=" + uid, + "-Djava.io.tmpdir=" + tmp.toAbsolutePath().toString(), + "-jar", file.getAbsolutePath()) + ); + command.addAll(processArgs); + ProcessBuilder pb = new ProcessBuilder(command) .redirectOutput(workDir.resolve("stdout.txt").toFile()) .redirectError(workDir.resolve("stderr.txt").toFile()); diff --git a/src/main/resources/swarm-app-args.properties b/src/main/resources/swarm-app-args.properties new file mode 100644 index 0000000..36c5a63 --- /dev/null +++ b/src/main/resources/swarm-app-args.properties @@ -0,0 +1 @@ +datasource/datasource-war/target/example-datasource-war-swarm.jar=-S h2 diff --git a/src/main/resources/swarm-apps.properties b/src/main/resources/swarm-apps.properties index 4c2092e..ec6ca55 100644 --- a/src/main/resources/swarm-apps.properties +++ b/src/main/resources/swarm-apps.properties @@ -1,6 +1,6 @@ #spring-boot-rest/target/demo-0.0.1-SNAPSHOT.jar=http://localhost:8080/ jaxrs/jaxrs-cdi/target/example-jaxrs-cdi-swarm.jar=http://localhost:8080/employees -datasource/datasource-subsystem/target/example-datasource-subsystem-swarm.jar=http://localhost:8080/ +datasource/datasource-war/target/example-datasource-war-swarm.jar=http://localhost:8080/ jpa-jaxrs-cdi/jpa-jaxrs-cdi/target/example-jpa-jaxrs-cdi-swarm.jar=http://localhost:8080/ messaging/messaging-mdb/target/example-messaging-mdb-swarm.jar=http://localhost:8080/ servlet/servlet-cdi/target/example-servlet-cdi-swarm.jar=http://localhost:8080/ From d1d981e9b8364cbfbceb9ad8f52886262d052bef Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 28 Feb 2018 12:07:33 +0100 Subject: [PATCH 2/2] trigger the GC not once but 10 times before measuring memory usage Triggering the GC multiple times makes the results slightly more reliable. --- src/main/java/org/wildfly/swarm/proc/Monitor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/wildfly/swarm/proc/Monitor.java b/src/main/java/org/wildfly/swarm/proc/Monitor.java index e87645f..08406fc 100644 --- a/src/main/java/org/wildfly/swarm/proc/Monitor.java +++ b/src/main/java/org/wildfly/swarm/proc/Monitor.java @@ -392,7 +392,9 @@ private void measureMemory(String id, String uid, Collector collector) throws Ex final ProcessFinder processFinder = new ProcessFinder(sigar); long pid = processFinder.findSingleProcess("State.Name.eq=java,Args.1.ct="+uid); - Jcmd.gc(pid); + for (int i = 0; i < 10; i++) { + Jcmd.gc(pid); + } ProcMem procMem = sigar.getProcMem(pid); long rss = procMem.getResident();