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

CODETOOLS-7902921: jcstress: Pre-warmup affinity support and thread pools #49

Merged
merged 1 commit into from
May 5, 2021
Merged
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
50 changes: 38 additions & 12 deletions jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.openjdk.jcstress.infra.runners.ForkedTestConfig;
import org.openjdk.jcstress.infra.runners.Runner;
import org.openjdk.jcstress.link.BinaryLinkClient;
import org.openjdk.jcstress.os.AffinitySupport;
import org.openjdk.jcstress.util.StringUtils;

import java.lang.reflect.Constructor;
@@ -49,24 +50,20 @@ public static void main(String[] args) throws Exception {
throw new IllegalStateException("Expected three arguments");
}

ExecutorService pool = Executors.newCachedThreadPool(new MyThreadFactory());

// Pre-initialize the affinity support and threads, so that workers
// do not have to do this on critical paths during the execution.
// This also runs when the rest of the infrastructure starts up.
pool.submit(new WarmupAffinityTask());
pool.submit(new EmptyTask());

String host = args[0];
int port = Integer.parseInt(args[1]);
int token = Integer.parseInt(args[2]);

BinaryLinkClient link = new BinaryLinkClient(host, port);

ExecutorService pool = Executors.newCachedThreadPool(new ThreadFactory() {
private final AtomicInteger id = new AtomicInteger();

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("jcstress-worker-" + id.incrementAndGet());
t.setDaemon(true);
return t;
}
});

ForkedTestConfig config = link.jobRequest(token);

TestResult result;
@@ -97,4 +94,33 @@ public Thread newThread(Runnable r) {
}
}

private static class MyThreadFactory implements ThreadFactory {
private final AtomicInteger id = new AtomicInteger();

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("jcstress-worker-" + id.incrementAndGet());
t.setDaemon(true);
return t;
}
}

private static class WarmupAffinityTask implements Runnable {
@Override
public void run() {
try {
AffinitySupport.tryBind();
} catch (Exception e) {
// Do not care
}
}
}

private static class EmptyTask implements Runnable {
@Override
public void run() {
// Do nothing
}
}
}