10. Why netty?
● Less GC
● Optimized for Linux based OS
● High performance buffers
11. Why netty?
● Less GC
● Optimized for Linux based OS
● High performance buffers
● Well defined threading model
12. Why netty?
● Less GC
● Optimized for Linux based OS
● High performance buffers
● Well defined threading model
● HTTP, HTTP/2, SPDY, SCTP, TCP,
UDP, UDT, MQTT, etc
28. Minimal setup
ServerBootstrap b = new ServerBootstrap();
b.group(
new NioEventLoopGroup(1),
new NioEventLoopGroup()
) .channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer() {...});
ChannelFuture f = b.bind(8080).sync();
f.channel().closeFuture().sync();
29. Minimal setup
ServerBootstrap b = new ServerBootstrap();
b.group(
new NioEventLoopGroup(1), //IO thread
new NioEventLoopGroup()
) .channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer() {...});
ChannelFuture f = b.bind(8080).sync();
f.channel().closeFuture().sync();
30. Minimal setup
ServerBootstrap b = new ServerBootstrap();
b.group(
new NioEventLoopGroup(1),
new NioEventLoopGroup() //worker threads
) .channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer() {...});
ChannelFuture f = b.bind(8080).sync();
f.channel().closeFuture().sync();
31. Minimal setup
ServerBootstrap b = new ServerBootstrap();
b.group(
new NioEventLoopGroup(1),
new NioEventLoopGroup() //worker threads
) .channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer() {...}); //pipeline init
ChannelFuture f = b.bind(8080).sync();
f.channel().closeFuture().sync();
80. Thread Model
ChannelFuture inCf = ctx.deregister();
inCf.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) {
targetLoop.register(cf.channel())
.addListener(completeHandler);
}
});
81. Reusing Event Loop
new ServerBootstrap().group(
new EpollEventLoopGroup(1),
new EpollEventLoopGroup()
).bind(80);
82. Reusing Event Loop
EventLoopGroup boss = new EpollEventLoopGroup(1);
EventLoopGroup workers = new EpollEventLoopGroup();
new ServerBootstrap().group(
boss,
workers
).bind(80);
new ServerBootstrap().group(
boss,
workers
).bind(443);