mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-11-05 18:51:25 +01:00
Using native transport (epoll) with netty
This commit is contained in:
parent
e0ec329402
commit
f22f204354
@ -16,7 +16,11 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
|
import io.netty.channel.ServerChannel;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||||
|
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||||
|
import io.netty.channel.epoll.EpollSocketChannel;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
@ -40,9 +44,10 @@ public class NettyMessagingService implements MessagingService {
|
|||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
private final Endpoint localEp;
|
private final Endpoint localEp;
|
||||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
private EventLoopGroup bossGroup;
|
||||||
private EventLoopGroup workerGroup;
|
private EventLoopGroup workerGroup;
|
||||||
private Class<? extends Channel> channelClass;
|
private Class<? extends Channel> clientChannelClass;
|
||||||
|
private Class<? extends ServerChannel> serverChannelClass;
|
||||||
private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>();
|
||||||
private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder()
|
private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder()
|
||||||
.maximumSize(100000)
|
.maximumSize(100000)
|
||||||
@ -55,8 +60,17 @@ public class NettyMessagingService implements MessagingService {
|
|||||||
|
|
||||||
// TODO: make this configurable.
|
// TODO: make this configurable.
|
||||||
private void initEventLoopGroup() {
|
private void initEventLoopGroup() {
|
||||||
|
try {
|
||||||
|
bossGroup = new EpollEventLoopGroup();
|
||||||
|
workerGroup = new EpollEventLoopGroup();
|
||||||
|
clientChannelClass = EpollSocketChannel.class;
|
||||||
|
serverChannelClass = EpollServerSocketChannel.class;
|
||||||
|
} catch (Throwable th) {
|
||||||
|
bossGroup = new NioEventLoopGroup();
|
||||||
workerGroup = new NioEventLoopGroup();
|
workerGroup = new NioEventLoopGroup();
|
||||||
channelClass = NioSocketChannel.class;
|
serverChannelClass = NioServerSocketChannel.class;
|
||||||
|
clientChannelClass = NioSocketChannel.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NettyMessagingService() {
|
public NettyMessagingService() {
|
||||||
@ -150,7 +164,7 @@ public class NettyMessagingService implements MessagingService {
|
|||||||
// TODO: Need JVM options to configure PooledByteBufAllocator.
|
// TODO: Need JVM options to configure PooledByteBufAllocator.
|
||||||
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||||
b.group(bossGroup, workerGroup)
|
b.group(bossGroup, workerGroup)
|
||||||
.channel(NioServerSocketChannel.class)
|
.channel(serverChannelClass)
|
||||||
.childHandler(new OnosCommunicationChannelInitializer())
|
.childHandler(new OnosCommunicationChannelInitializer())
|
||||||
.option(ChannelOption.SO_BACKLOG, 128)
|
.option(ChannelOption.SO_BACKLOG, 128)
|
||||||
.childOption(ChannelOption.SO_KEEPALIVE, true);
|
.childOption(ChannelOption.SO_KEEPALIVE, true);
|
||||||
@ -181,7 +195,7 @@ public class NettyMessagingService implements MessagingService {
|
|||||||
bootstrap.group(workerGroup);
|
bootstrap.group(workerGroup);
|
||||||
// TODO: Make this faster:
|
// TODO: Make this faster:
|
||||||
// http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0
|
// http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0
|
||||||
bootstrap.channel(channelClass);
|
bootstrap.channel(clientChannelClass);
|
||||||
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
|
||||||
bootstrap.handler(new OnosCommunicationChannelInitializer());
|
bootstrap.handler(new OnosCommunicationChannelInitializer());
|
||||||
// Start the client.
|
// Start the client.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user