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

Disable socket factory for pre JDK11 #2633

Merged
merged 1 commit into from Feb 5, 2020

Conversation

Lewuathe
Copy link
Member

Purpose

As discussed in #1169, the socket channel is the cause of the slowdown with JDK 11. As JDK-8131133 is fixed from JDK 9, the workaround is not necessary anymore. We can safely disable the socket factory usage if the runtime is JDK 11 or later. Confirmed the communication between server and client works well even with HTTP 2.

Overview

  • Add JavaVersion class from presto-server module to parse Java version string. Although we expected to use Runtime.getVersion, it does not exist in pre-JDK 9.
  • Check runtime version and disable socket factory if JDK 11 or later.

@cla-bot cla-bot bot added the cla-signed label Jan 27, 2020
@rohangarg
Copy link
Member

should this change (disabling SocketChannelSocketFactory) also be done for PrestoDriver?

@findepi findepi requested a review from electrum January 27, 2020 10:13
@Lewuathe
Copy link
Member Author

@rohangarg Good catch. Thanks! The same problem happens for presto-jdbc too.
I'm going to update accordingly.

@Lewuathe
Copy link
Member Author

Checkstyle error happening in CI seems to be unrelated to the change.

[ERROR] src/main/java/io/prestosql/tests/product/launcher/env/EnvironmentModule.java:[40] (imports) ImportOrder: Wrong order for 'io.prestosql.tests.product.launcher.env.environment.SinglenodeLdap' import.

@ebyhr
Copy link
Member

ebyhr commented Jan 30, 2020

Could you rebase and push again? It should be fixed in da29dad.

@Lewuathe Lewuathe force-pushed the disable-socket-factory-pre-JDK11 branch from 0ec30fe to 56adbcc Compare January 30, 2020 08:28
@martint
Copy link
Member

martint commented Jan 31, 2020

There's a build failure:

[ERROR] src/main/java/io/prestosql/cli/QueryRunner.java:[16,8] (imports) UnusedImports: Unused import - com.google.common.base.StandardSystemProperty.

The change looks good. Can you squash the commits? I'll merge it once you do that and the build passes.

@Lewuathe Lewuathe force-pushed the disable-socket-factory-pre-JDK11 branch 2 times, most recently from 9f0054f to 4d74f15 Compare January 31, 2020 12:32
@martint martint self-assigned this Jan 31, 2020
Copy link
Member

@electrum electrum left a comment

Choose a reason for hiding this comment

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

Let’s simplify the JDK 11 detection to be more robust.


// TODO: remove this when we upgrade to Java 9 (replace with java.lang.Runtime.getVersion())
// It's copied from io.prestosql.server module.
public class JavaVersion
Copy link
Member

@electrum electrum Jan 31, 2020

Choose a reason for hiding this comment

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

I’m concerned about having this complex code (which has had bugs in the past) as part of the JDBC driver, which runs in various environments. We also plan to keep the driver on Java 8 for the foreseeable future, so this code won’t be removed anytime soon.

Some alternatives:

  1. Just split on a period and take the first item, since that works for all versions.

  2. Use reflection to check for and call the Runtime.Version API. We can check for and use the feature method which is in JDK 10+.

  3. Use reflection to look for the existence of a “marker” class like java.net.http.HttpClient which was added in JDK 11.

Copy link
Member

Choose a reason for hiding this comment

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

This is the code using Runtime.version() reflectively:

@SuppressWarnings("JavaReflectionMemberAccess")
private static boolean isAtLeastJava11()
{
    try {
        Method versionMethod = Runtime.class.getMethod("version");
        Method featureMethod = versionMethod.getReturnType().getMethod("feature");
        Object version = versionMethod.invoke(null);
        int feature = (int) featureMethod.invoke(version);
        return feature >= 11;
    }
    catch (ReflectiveOperationException e) {
        return false;
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

Code to safely parse the version:

private static boolean isAtLeastJava11()
{
    String feature = Splitter.on(".").split(StandardSystemProperty.JAVA_VERSION.value()).next();
    try {
        return Integer.parseInt(feature) >= 11;
    }
    catch (NumberFormatException e) {
        return false;
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

@dain agrees we should go with option 1, since that's simple and reliable

Copy link
Member

@electrum electrum left a comment

Choose a reason for hiding this comment

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

Please squash the commits when updating

presto-cli/src/main/java/io/prestosql/cli/QueryRunner.java Outdated Show resolved Hide resolved
@Lewuathe Lewuathe force-pushed the disable-socket-factory-pre-JDK11 branch 3 times, most recently from 1d8e60f to 9188182 Compare February 2, 2020 03:14
@Lewuathe Lewuathe force-pushed the disable-socket-factory-pre-JDK11 branch from 9188182 to 9927836 Compare February 2, 2020 04:04
@electrum electrum merged commit 81b2dab into trinodb:master Feb 5, 2020
@electrum
Copy link
Member

electrum commented Feb 5, 2020

Thanks!

@Lewuathe Lewuathe deleted the disable-socket-factory-pre-JDK11 branch February 7, 2020 06:30
@electrum electrum mentioned this pull request Feb 15, 2020
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants