Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the datasources example #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/main/java/org/wildfly/swarm/proc/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,20 +183,28 @@ 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();

if (!file.exists())
throw new RuntimeException("File does not exist: " + file.getAbsolutePath());

List<String> 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);
}
Expand Down Expand Up @@ -269,9 +280,10 @@ private Optional<ArchivedResult> 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<String> processArgs, final Collector collector) {

System.out.println("Testing " + file.getAbsolutePath() + ", iteration " + iteration);
String id = file.getAbsolutePath();
Expand All @@ -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<String> 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());

Expand Down Expand Up @@ -376,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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more helps better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My very non-scientific experience is that 1 GC cycle isn't enough to collect everything. I'm not sure if we have many objects with finalizers (or in reference queues), but that's one reason why at least 2 GC cycles are required to clean up properly.


ProcMem procMem = sigar.getProcMem(pid);
long rss = procMem.getResident();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/swarm-app-args.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
datasource/datasource-war/target/example-datasource-war-swarm.jar=-S h2
2 changes: 1 addition & 1 deletion src/main/resources/swarm-apps.properties
Original file line number Diff line number Diff line change
@@ -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/