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

TableServiceAsyncTest: Eliminate Compiler Overhead Variance; Close QueryCompiler's JavaFileManager #4808

Merged
merged 6 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -683,19 +683,60 @@ private void maybeCreateClass(String className, String code, String packageName,
}
}

private static JavaCompiler JAVA_COMPILER = null;
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved

private static JavaCompiler getJavaCompiler() {
JavaCompiler localCompiler = JAVA_COMPILER;
if (localCompiler != null) {
return localCompiler;
}
synchronized (QueryCompiler.class) {
localCompiler = JAVA_COMPILER;
if (localCompiler != null) {
return localCompiler;
}
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
localCompiler = JAVA_COMPILER = ToolProvider.getSystemJavaCompiler();
if (localCompiler == null) {
throw new RuntimeException("No Java compiler provided - are you using a JRE instead of a JDK?");
}
}
return localCompiler;
}

/**
* While the JavaFileManager should be closed to clean up resources, using a singleton avoids repeated processing of
* the classpath, which is <b>very</b> expensive.
*/
private static JavaFileManager JAVA_FILE_MANAGER = null;

private static JavaFileManager getJavaFileManager() {
JavaFileManager localManager = JAVA_FILE_MANAGER;
if (localManager != null) {
return localManager;
}
synchronized (QueryCompiler.class) {
localManager = JAVA_FILE_MANAGER;
if (localManager != null) {
return localManager;
}
localManager = JAVA_FILE_MANAGER = getJavaCompiler().getStandardFileManager(null, null, null);
if (localManager == null) {
throw new RuntimeException("No Java compiler provided - are you using a JRE instead of a JDK?");
}
}
return localManager;
}

private void maybeCreateClassHelper(String fqClassName, String finalCode, String[] splitPackageName,
String rootPathAsString, String tempDirAsString) {
final StringWriter compilerOutput = new StringWriter();

final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new RuntimeException("No Java compiler provided - are you using a JRE instead of a JDK?");
}
final JavaCompiler compiler = getJavaCompiler();

final String classPathAsString = getClassPath() + File.pathSeparator + getJavaClassPath();
final List<String> compilerOptions = Arrays.asList("-d", tempDirAsString, "-cp", classPathAsString);

final StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
final JavaFileManager fileManager = getJavaFileManager();

final boolean result = compiler.getTask(compilerOutput,
fileManager,
Expand Down Expand Up @@ -735,7 +776,7 @@ private void maybeCreateClassHelper(String fqClassName, String finalCode, String
* @return a Pair of success, and the compiler output
*/
private Pair<Boolean, String> tryCompile(File basePath, Collection<File> javaFiles) throws IOException {
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
final JavaCompiler compiler = getJavaCompiler();
if (compiler == null) {
throw new RuntimeException("No Java compiler provided - are you using a JRE instead of a JDK?");
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
}
nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class TableServiceAsyncTest extends DeephavenSessionTestBase {

private static final Duration GETTIME = Duration.ofSeconds(15);
private static final int CHAIN_OPS = 50;
private static final int CHAIN_OPS = 250;
private static final int CHAIN_ROWS = 1000;

@Test(timeout = 20000)
Expand Down Expand Up @@ -93,8 +93,11 @@ private static List<TableSpec> createLongChain(int numColumns, int numRows) {
if (i == 0) {
longChain.add(TableSpec.empty(numRows).view("I_0=ii"));
} else {
// create a chain using the previous table even though we don't need the data
final TableSpec prev = longChain.get(i - 1);
longChain.add(prev.updateView("I_" + i + " = 1 + I_" + (i - 1)));
// to avoid timeouts due to compilation variance reuse the same expression, including the destination
// column which shows up in the generated formula's FormulaEvaluationException
longChain.add(prev.updateView("I_1 = 1 + I_0"));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how this is directly related to #4798; that is specifically around a timeout error. I'd assume in the case of too many open files in the compilation path there will be some other error that causes TableServiceAsyncTest to fail, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Everytime it was timed out the server was in the middle of compiling. I did a bunch of instrumentation - there is no real issue with the test, just that the variance of compilation causes it to time out. Repeated local runs are actually harder to time out because the classes have been precompiled.

The change that you are commenting on here, is the actual fix -- run the long chain without repeatedly invoking the compiler. If you prefer, we can split this out from the singleton creation.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, makes sense; I never saw that high of variation likely due to the points you bring up.

nbauernfeind marked this conversation as resolved.
Show resolved Hide resolved
}
}
return longChain;
Expand Down
Loading