diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index 1d95418ba9..478750b075 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -32,16 +32,20 @@ configurations { } dependencies { - compile project(':grpc-core'), - project(':grpc-netty'), - project(':grpc-okhttp'), - project(':grpc-stub'), - project(':grpc-integration-testing'), - libraries.junit, - libraries.mockito, - libraries.hdrhistogram, - libraries.netty_tcnative, - libraries.netty_transport_native_epoll + List deps = [project(':grpc-core'), + project(':grpc-netty'), + project(':grpc-okhttp'), + project(':grpc-stub'), + project(':grpc-integration-testing'), + libraries.junit, + libraries.mockito, + libraries.hdrhistogram] + if (osdetector.os == "linux") { + // These are only available on linux. + deps += [libraries.netty_tcnative, libraries.netty_transport_native_epoll] + } + + compile deps alpnboot alpnboot_package_name } diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java index c8634ff94d..a8e4e2cc03 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java @@ -72,8 +72,6 @@ import io.grpc.transport.netty.NegotiationType; import io.grpc.transport.netty.NettyChannelBuilder; import io.grpc.transport.okhttp.OkHttpChannelBuilder; import io.netty.channel.EventLoopGroup; -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.handler.ssl.SslContext; @@ -201,8 +199,18 @@ public class AsyncClient { final EventLoopGroup group; final Class channelType; if (config.nettyNativeTransport) { - group = new EpollEventLoopGroup(); - channelType = EpollSocketChannel.class; + 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; + } catch (Exception e) { + throw new RuntimeException(e); + } } else { group = new NioEventLoopGroup(); channelType = NioSocketChannel.class; diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java index 6207d8ddf9..808a8562ba 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java @@ -50,8 +50,6 @@ import io.grpc.transport.netty.GrpcSslContexts; import io.grpc.transport.netty.NettyServerBuilder; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; -import io.netty.channel.epoll.EpollEventLoopGroup; -import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.ssl.SslContext; @@ -104,9 +102,18 @@ public class AsyncServer { final EventLoopGroup worker; final Class channelType; if (nettyNativeTransport) { - boss = new EpollEventLoopGroup(); - worker = new EpollEventLoopGroup(); - channelType = EpollServerSocketChannel.class; + 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.EpollServerSocketChannel"); + boss = (EventLoopGroup) groupClass.newInstance(); + worker = (EventLoopGroup) groupClass.newInstance(); + channelType = channelClass; + } catch (Exception e) { + throw new RuntimeException(e); + } } else { boss = new NioEventLoopGroup(); worker = new NioEventLoopGroup();