diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index 8a01f523305..5a45187f500 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -39,12 +39,9 @@ dependencies { project(':grpc-interop-testing'), libraries.junit, libraries.mockito, - libraries.hdrhistogram - if (osdetector.os == "linux") { - // These are only available on linux. - compile libraries.netty_tcnative, - libraries.netty_transport_native_epoll - } + libraries.hdrhistogram, + libraries.netty_tcnative, + libraries.netty_transport_native_epoll alpnboot alpnboot_package_name } diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/Utils.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/Utils.java index 38e55e16b47..0508d93680f 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/Utils.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/Utils.java @@ -44,8 +44,12 @@ import io.grpc.transport.netty.NettyChannelBuilder; import io.grpc.transport.okhttp.OkHttpChannelBuilder; import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.EpollDomainSocketChannel; +import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.channel.unix.DomainSocketAddress; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslProvider; @@ -79,24 +83,22 @@ static boolean parseBoolean(String value) { static SocketAddress parseSocketAddress(String value) { if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) { // Unix Domain Socket address. + // Create the underlying file for the Unix Domain Socket. + String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length()); + File file = new File(filePath); + if (!file.isAbsolute()) { + throw new IllegalArgumentException("File path must be absolute: " + filePath); + } try { - // Create the underlying file for the Unix Domain Socket. - String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length()); - File file = new File(filePath); - if (!file.isAbsolute()) { - throw new IllegalArgumentException("File path must be absolute: " + filePath); - } if (file.createNewFile()) { // If this application created the file, delete it when the application exits. file.deleteOnExit(); } - // Create the SocketAddress referencing the file. - Class addressClass = Class.forName("io.netty.channel.unix.DomainSocketAddress"); - return (SocketAddress) addressClass.getDeclaredConstructor(File.class) - .newInstance(file); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (IOException ex) { + throw new RuntimeException(ex); } + // Create the SocketAddress referencing the file. + return new DomainSocketAddress(file); } else { // Standard TCP/IP address. String[] parts = value.split(":", 2); @@ -146,45 +148,26 @@ static Channel newClientChannel(ClientConfiguration config) throws IOException { final EventLoopGroup group; final Class channelType; switch (config.transport) { - case NETTY_NIO: { + case NETTY_NIO: group = new NioEventLoopGroup(); channelType = NioSocketChannel.class; break; - } - case NETTY_EPOLL: { - try { - // These classes are only available on linux. - Class groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup"); - @SuppressWarnings("unchecked") - Class channelClass = - (Class) Class.forName( - "io.netty.channel.epoll.EpollSocketChannel"); - group = (EventLoopGroup) groupClass.newInstance(); - channelType = channelClass; - break; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - case NETTY_UNIX_DOMAIN_SOCKET: { - try { - // These classes are only available on linux. - Class groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup"); - @SuppressWarnings("unchecked") - Class channelClass = - (Class) Class.forName( - "io.netty.channel.epoll.EpollDomainSocketChannel"); - group = (EventLoopGroup) groupClass.newInstance(); - channelType = channelClass; - break; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - default: { + + case NETTY_EPOLL: + // These classes only work on Linux. + group = new EpollEventLoopGroup(); + channelType = EpollSocketChannel.class; + break; + + case NETTY_UNIX_DOMAIN_SOCKET: + // These classes only work on Linux. + group = new EpollEventLoopGroup(); + channelType = EpollDomainSocketChannel.class; + break; + + default: // Should never get here. throw new IllegalArgumentException("Unsupported transport: " + config.transport); - } } return NettyChannelBuilder .forAddress(config.address) diff --git a/build.gradle b/build.gradle index 6d2289afa9c..55896f8417a 100644 --- a/build.gradle +++ b/build.gradle @@ -93,6 +93,16 @@ subprojects { } } + def tcnative_suffix = ""; + if (osdetector.classifier in ["linux-x86_64", "osx-x86_64", "windows-x86_64"]) { + // The native code is only pre-compiled on certain platforms. + tcnative_suffix = ":" + osdetector.classifier + } + def epoll_suffix = ""; + if (osdetector.classifier in ["linux-x86_64"]) { + // The native code is only pre-compiled on certain platforms. + epoll_suffix = ":" + osdetector.classifier + } libraries = [ guava: 'com.google.guava:guava:18.0', // used to collect benchmark results @@ -108,8 +118,8 @@ subprojects { protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.4.1', netty: 'io.netty:netty-codec-http2:4.1.0.Beta5', - netty_tcnative: "io.netty:netty-tcnative:1.1.33.Fork2:${osdetector.classifier}", - netty_transport_native_epoll: "io.netty:netty-transport-native-epoll:4.1.0.Beta5:${osdetector.classifier}", + netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork2' + tcnative_suffix, + netty_transport_native_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.Beta5' + epoll_suffix, // Test dependencies. junit: 'junit:junit:4.11',