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

Reduce ops when setting exisitng execution env #9967

Merged
merged 2 commits into from
May 16, 2024
Merged
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
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,16 @@ lazy val `profiling-utils` = project
exclude ("org.netbeans.api", "org-openide-awt")
exclude ("org.netbeans.api", "org-openide-modules")
exclude ("org.netbeans.api", "org-netbeans-api-annotations-common"),
"org.slf4j" % "slf4j-api" % slf4jVersion,
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test
),
modulePath := {
JPMSUtils.filterModulesFromUpdate(
update.value,
Seq(
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
"org.slf4j" % "slf4j-api" % slf4jVersion
),
streams.value.log,
shouldContainAll = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,34 @@ public Future<BoxedUnit> executeAsynchronously(RuntimeContext ctx, ExecutionCont
private void setExecutionEnvironment(
Runtime$Api$ExecutionEnvironment executionEnvironment, UUID contextId, RuntimeContext ctx) {
var logger = ctx.executionService().getLogger();
ctx.jobControlPlane().abortJobs(contextId);
var contextLockTimestamp = ctx.locking().acquireContextLock(contextId);

try {
var writeLockTimestamp = ctx.locking().acquireWriteCompilationLock();
try {
Stack<InstrumentFrame> stack = ctx.contextManager().getStack(contextId);
ctx.executionService()
.getContext()
.setExecutionEnvironment(ExecutionEnvironment.forName(executionEnvironment.name()));
CacheInvalidation.invalidateAll(stack);
ctx.jobProcessor().run(ExecuteJob.apply(contextId, stack.toList()));
reply(new Runtime$Api$SetExecutionEnvironmentResponse(contextId), ctx);
} finally {
ctx.locking().releaseWriteCompilationLock();
var oldEnvironment = ctx.executionService().getContext().getExecutionEnvironment();
if (!oldEnvironment.getName().equals(executionEnvironment.name())) {
ctx.jobControlPlane().abortJobs(contextId);
var writeLockTimestamp = ctx.locking().acquireWriteCompilationLock();
try {
Stack<InstrumentFrame> stack = ctx.contextManager().getStack(contextId);
ctx.executionService()
.getContext()
.setExecutionEnvironment(ExecutionEnvironment.forName(executionEnvironment.name()));
CacheInvalidation.invalidateAll(stack);
ctx.jobProcessor().run(ExecuteJob.apply(contextId, stack.toList()));
reply(new Runtime$Api$SetExecutionEnvironmentResponse(contextId), ctx);
} finally {
ctx.locking().releaseWriteCompilationLock();
logger.log(
Level.FINEST,
"Kept write compilation lock [SetExecutionEnvironmentCommand] for "
+ (System.currentTimeMillis() - writeLockTimestamp)
+ " milliseconds");
}
} else {
logger.log(
Level.FINEST,
"Kept write compilation lock [SetExecutionEnvironmentCommand] for "
+ (System.currentTimeMillis() - writeLockTimestamp)
+ " milliseconds");
"Requested environment is the same as the current one. Request has no effect");
reply(new Runtime$Api$SetExecutionEnvironmentResponse(contextId), ctx);
}
} finally {
ctx.locking().releaseContextLock(contextId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@ class RuntimeExecutionEnvironmentTest
.Design()
.name

// setting execution environment to the existing one has no effect
context.send(
Api.Request(
requestId,
Api.SetExecutionEnvironmentRequest(
contextId,
Api.ExecutionEnvironment.Design()
)
)
)

context.receiveNIgnoreStdLib(1) should contain theSameElementsAs Seq(
Api.Response(requestId, Api.SetExecutionEnvironmentResponse(contextId))
)
context.languageContext.getExecutionEnvironment.getName shouldEqual Api.ExecutionEnvironment
.Design()
.name

// set execution environment
context.send(
Api.Request(
Expand Down
1 change: 1 addition & 0 deletions lib/scala/profiling-utils/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module org.enso.profiling {
requires org.netbeans.modules.sampler.RELEASE180;
requires jdk.management;
requires org.slf4j;

exports org.enso.profiling.sampler;
exports org.enso.profiling.events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.IOException;
import java.io.OutputStream;
import org.netbeans.modules.sampler.Sampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Gathers application performance statistics that can be visualised in Java VisualVM, and writes it
Expand All @@ -19,6 +21,8 @@ public final class OutputStreamSampler implements MethodsSampler {

private boolean isSamplingStarted = false;

private static Logger logger = LoggerFactory.getLogger(OutputStreamSampler.class);

/**
* Creates the {@link OutputStreamSampler} for provided output stream.
*
Expand All @@ -36,6 +40,7 @@ public static OutputStreamSampler ofFile(File file) throws FileNotFoundException
public void start() {
synchronized (this) {
if (sampler != null && !isSamplingStarted) {
logger.trace("Starting profiling sampler");
sampler.start();
isSamplingStarted = true;
}
Expand All @@ -46,6 +51,7 @@ public void start() {
public void stop() throws IOException {
synchronized (this) {
if (isSamplingStarted) {
logger.trace("Stopping profiling sampler");
try (DataOutputStream dos = new DataOutputStream(outputStream)) {
sampler.stopAndWriteTo(dos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ class Runner(
else Seq()

val command = Seq(javaCommand.executableName) ++
jvmArguments ++ loggingConnectionArguments ++ runSettings.runnerArguments
Seq(
"-XX:ActiveProcessorCount=2",
"-Xmx8192m"
Comment on lines +226 to +227
Copy link
Member

Choose a reason for hiding this comment

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

@hubertp Just randomly browsing through recent PRs, I have noticed this change. I assume it has something to do with performance. Could you share how the performance was affected? And give us more insight on why you have chosen these two cmdline options?

//"-agentlib:jdwp=transport=dt_socket,server=y,address=localhost:5005,suspend=y"
) ++ jvmArguments ++ loggingConnectionArguments ++ runSettings.runnerArguments

val distributionSettings =
distributionManager.getEnvironmentToInheritSettings
Expand Down
Loading