This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch driver-35 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit f32a49bc623014446e56e55563bdeb7ddcd2d1a9 Author: stephen <[email protected]> AuthorDate: Fri Dec 6 19:23:44 2019 -0500 Add epoll support for the driver --- .../main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java | 9 +++++++-- .../apache/tinkerpop/gremlin/driver/DefaultConnectionPool.java | 9 +++++++-- .../apache/tinkerpop/gremlin/driver/simple/AbstractClient.java | 1 - .../tinkerpop/gremlin/server/GremlinServerIntegrateTest.java | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java index 7763cb0..d6bc028 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java @@ -22,6 +22,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.Epoll; +import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; @@ -844,8 +846,11 @@ public final class Cluster { public Factory(final int nioPoolSize) { final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("gremlin-driver-loop-%d").build(); - // TODO: Enable epoll if available. - group = new NioEventLoopGroup(nioPoolSize, threadFactory); + + if (Epoll.isAvailable()) + group = new EpollEventLoopGroup(nioPoolSize, threadFactory); + else + group = new NioEventLoopGroup(nioPoolSize, threadFactory); } Bootstrap createBootstrap() { diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/DefaultConnectionPool.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/DefaultConnectionPool.java index fec46e6..7bda3d5 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/DefaultConnectionPool.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/DefaultConnectionPool.java @@ -20,6 +20,8 @@ package org.apache.tinkerpop.gremlin.driver; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; +import io.netty.channel.epoll.Epoll; +import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.pool.ChannelHealthChecker; @@ -98,8 +100,11 @@ public class DefaultConnectionPool implements ConnectionPool { final Bootstrap b = cluster.getFactory().createBootstrap(); b.remoteAddress(host.getHostUri().getHost(), host.getHostUri().getPort()); - // TODO: Use Epoll if available - b.channel(NioSocketChannel.class); + + if (Epoll.isAvailable()) + b.channel(EpollSocketChannel.class); + else + b.channel(NioSocketChannel.class); final ChannelPoolHandler handler = new ChannelPoolHandler() { @Override diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java index 93fe727..4fb950c 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/AbstractClient.java @@ -42,7 +42,6 @@ public abstract class AbstractClient implements SimpleClient { public AbstractClient(final String threadPattern) { final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern(threadPattern).build(); - // TODO: Use Epoll if available group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory); } diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java index abe63e2..5f16089 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java @@ -828,7 +828,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration // // went with two possible error messages here as i think that there is some either non-deterministic // behavior around the error message or it's environmentally dependent (e.g. different jdk, versions, etc) - assertThat(root.getMessage(), Matchers.anyOf(is("Connection to server is no longer active"), is("Connection reset by peer"))); + assertThat(root.getMessage(), Matchers.anyOf(containsString("Connection to server is no longer active"), containsString("Connection reset by peer"))); // validate that we can still send messages to the server assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
