Skip to content

Conversation

@xiazcy
Copy link
Owner

@xiazcy xiazcy commented Sep 21, 2021

public final EventLoopGroup group;
// Checks and uses Epoll if it is available. ref: http://netty.io/wiki/native-transports.html
// Subclasses also depend on if Epoll is available or not, so making this protected
protected boolean isEpollAvailable;

Choose a reason for hiding this comment

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

I'm not quite convinced this is necessary as it's just a wrapper around Epoll.isAvailable().

Or, in other words, what is kind of concerning to me in this PR is that we are calling Epoll.isAvailable() in many places, but then again it looks like the logic of what to do after checking it is difference so having this consolidated in one place doesn't even seem really feasible.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I guess there isn't any difference, so you mean to just use Epoll.isAvailable() directly?

Choose a reason for hiding this comment

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

Yeah.

Like, it would make sense to wrap it if we had like a function that returns a EventLoopGroup pool and it abstracted this away, but it looks like we still end up needing to call Epoll.isAvailable() directly anyways so it's pointless.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Makes sense, I'll change them then.

final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("gremlin-driver-loop-%d").build();
group = new NioEventLoopGroup(nioPoolSize, threadFactory);
// Checks and uses Epoll if it is available. ref: http://netty.io/wiki/native-transports.html
group = Epoll.isAvailable()? new EpollEventLoopGroup(nioPoolSize, threadFactory) : new NioEventLoopGroup(nioPoolSize, threadFactory);

Choose a reason for hiding this comment

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

Nit: Add space before ?

final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern(threadPattern).build();
group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory);
// Checks and uses Epoll if it is available. ref: http://netty.io/wiki/native-transports.html
group = Epoll.isAvailable()? new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory)

Choose a reason for hiding this comment

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

nit ? missing space before

final MessageSerializer serializer = new GryoMessageSerializerV3d0();
b.channel(NioSocketChannel.class)
// Checks and uses Epoll if it is available. ref: http://netty.io/wiki/native-transports.html
b.channel(Epoll.isAvailable()? EpollSocketChannel.class : NioSocketChannel.class)

Choose a reason for hiding this comment

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

same

public void shouldUseEpollIfAvailable() throws Exception {
final WebSocketClient client = new WebSocketClient();
if (Epoll.isAvailable()) {
assertTrue(client.group instanceof EpollEventLoopGroup);

Choose a reason for hiding this comment

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

Nit: assertTrue(client.group instanceof (Epoll.isAvailable() ? EpollEventLoopGroup : NioEventLoopGroup));

Copy link
Owner Author

@xiazcy xiazcy Sep 22, 2021

Choose a reason for hiding this comment

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

Using ternary operator gives an Expression expected error on the two values, which I guess it's because the ternary operator is looking for a variable to assign the values to based on the condition, but we are using this as a statement. So I will leave this with the if/else.

assertTrue(client.group instanceof NioEventLoopGroup);
}
}
}

Choose a reason for hiding this comment

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

Nit - should add new line, even though they didn't have it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants