Madan Jampani

Netty native transport (epoll) support

...@@ -22,10 +22,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterMessage; ...@@ -22,10 +22,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterMessage;
22 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; 22 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
23 import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse; 23 import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse;
24 import org.onlab.onos.store.cluster.messaging.MessageSubject; 24 import org.onlab.onos.store.cluster.messaging.MessageSubject;
25 -import org.onlab.onos.store.serializers.ClusterMessageSerializer;
26 import org.onlab.onos.store.serializers.KryoNamespaces; 25 import org.onlab.onos.store.serializers.KryoNamespaces;
27 import org.onlab.onos.store.serializers.KryoSerializer; 26 import org.onlab.onos.store.serializers.KryoSerializer;
28 -import org.onlab.onos.store.serializers.MessageSubjectSerializer;
29 import org.onlab.util.KryoNamespace; 27 import org.onlab.util.KryoNamespace;
30 import org.onlab.netty.Endpoint; 28 import org.onlab.netty.Endpoint;
31 import org.onlab.netty.Message; 29 import org.onlab.netty.Message;
......
...@@ -17,6 +17,8 @@ import io.netty.channel.ChannelInitializer; ...@@ -17,6 +17,8 @@ import io.netty.channel.ChannelInitializer;
17 import io.netty.channel.ChannelOption; 17 import io.netty.channel.ChannelOption;
18 import io.netty.channel.EventLoopGroup; 18 import io.netty.channel.EventLoopGroup;
19 import io.netty.channel.SimpleChannelInboundHandler; 19 import io.netty.channel.SimpleChannelInboundHandler;
20 +import io.netty.channel.epoll.EpollEventLoopGroup;
21 +import io.netty.channel.epoll.EpollSocketChannel;
20 import io.netty.channel.nio.NioEventLoopGroup; 22 import io.netty.channel.nio.NioEventLoopGroup;
21 import io.netty.channel.socket.SocketChannel; 23 import io.netty.channel.socket.SocketChannel;
22 import io.netty.channel.socket.nio.NioServerSocketChannel; 24 import io.netty.channel.socket.nio.NioServerSocketChannel;
...@@ -41,7 +43,8 @@ public class NettyMessagingService implements MessagingService { ...@@ -41,7 +43,8 @@ public class NettyMessagingService implements MessagingService {
41 private final int port; 43 private final int port;
42 private final Endpoint localEp; 44 private final Endpoint localEp;
43 private final EventLoopGroup bossGroup = new NioEventLoopGroup(); 45 private final EventLoopGroup bossGroup = new NioEventLoopGroup();
44 - private final EventLoopGroup workerGroup = new NioEventLoopGroup(); 46 + private EventLoopGroup workerGroup;
47 + private Class<? extends Channel> channelClass;
45 private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>(); 48 private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>();
46 private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder() 49 private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder()
47 .maximumSize(100000) 50 .maximumSize(100000)
...@@ -52,6 +55,17 @@ public class NettyMessagingService implements MessagingService { ...@@ -52,6 +55,17 @@ public class NettyMessagingService implements MessagingService {
52 private final GenericKeyedObjectPool<Endpoint, Channel> channels 55 private final GenericKeyedObjectPool<Endpoint, Channel> channels
53 = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory()); 56 = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory());
54 57
58 + // TODO: make this configurable.
59 + private void initEventLoopGroup() {
60 + try {
61 + workerGroup = new EpollEventLoopGroup();
62 + channelClass = EpollSocketChannel.class;
63 + } catch (Throwable t) {
64 + workerGroup = new NioEventLoopGroup();
65 + channelClass = NioSocketChannel.class;
66 + }
67 + }
68 +
55 public NettyMessagingService() { 69 public NettyMessagingService() {
56 // TODO: Default port should be configurable. 70 // TODO: Default port should be configurable.
57 this(8080); 71 this(8080);
...@@ -71,6 +85,7 @@ public class NettyMessagingService implements MessagingService { ...@@ -71,6 +85,7 @@ public class NettyMessagingService implements MessagingService {
71 public void activate() throws Exception { 85 public void activate() throws Exception {
72 channels.setTestOnBorrow(true); 86 channels.setTestOnBorrow(true);
73 channels.setTestOnReturn(true); 87 channels.setTestOnReturn(true);
88 + initEventLoopGroup();
74 startAcceptingConnections(); 89 startAcceptingConnections();
75 } 90 }
76 91
...@@ -173,7 +188,7 @@ public class NettyMessagingService implements MessagingService { ...@@ -173,7 +188,7 @@ public class NettyMessagingService implements MessagingService {
173 bootstrap.group(workerGroup); 188 bootstrap.group(workerGroup);
174 // TODO: Make this faster: 189 // TODO: Make this faster:
175 // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0 190 // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0
176 - bootstrap.channel(NioSocketChannel.class); 191 + bootstrap.channel(channelClass);
177 bootstrap.option(ChannelOption.SO_KEEPALIVE, true); 192 bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
178 bootstrap.handler(new OnosCommunicationChannelInitializer()); 193 bootstrap.handler(new OnosCommunicationChannelInitializer());
179 // Start the client. 194 // Start the client.
......