Search in sources :

Example 51 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project ambry by linkedin.

the class NettyServer method start.

@Override
public void start() throws InstantiationException {
    long startupBeginTime = System.currentTimeMillis();
    try {
        logger.trace("Starting NettyServer deployment");
        if (Epoll.isAvailable()) {
            logger.trace("Using EpollEventLoopGroup in NettyServer.");
            bossGroup = new EpollEventLoopGroup(nettyConfig.nettyServerBossThreadCount);
            workerGroup = new EpollEventLoopGroup(nettyConfig.nettyServerWorkerThreadCount);
        } else {
            bossGroup = new NioEventLoopGroup(nettyConfig.nettyServerBossThreadCount);
            workerGroup = new NioEventLoopGroup(nettyConfig.nettyServerWorkerThreadCount);
        }
        for (Map.Entry<Integer, ChannelInitializer<SocketChannel>> entry : channelInitializers.entrySet()) {
            bindServer(entry.getKey(), entry.getValue(), bossGroup, workerGroup);
        }
        nettyMetrics.registerNettyPendingTasksGauge(bossGroup, "Boss");
        nettyMetrics.registerNettyPendingTasksGauge(workerGroup, "Worker");
    } catch (InterruptedException e) {
        logger.error("NettyServer start await was interrupted", e);
        nettyMetrics.nettyServerStartError.inc();
        throw new InstantiationException("Netty server bind to port [" + nettyConfig.nettyServerPort + "] was interrupted");
    } finally {
        long startupTime = System.currentTimeMillis() - startupBeginTime;
        logger.info("NettyServer start took {} ms", startupTime);
        nettyMetrics.nettyServerStartTimeInMs.update(startupTime);
    }
}
Also used : EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) Map(java.util.Map) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 52 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project lispflowmapping by opendaylight.

the class LispSouthboundPlugin method init.

public void init() {
    LOG.info("LISP (RFC6830) Southbound Plugin is initializing...");
    synchronized (startLock) {
        this.akdb = new AuthKeyDb(new HashMapDb());
        this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, akdb);
        this.dsbe = new DataStoreBackEnd(dataBroker);
        restoreDaoFromDatastore();
        LispSouthboundHandler lsbh = new LispSouthboundHandler(this);
        this.lispSouthboundHandler = lsbh;
        LispXtrSouthboundHandler lxsbh = new LispXtrSouthboundHandler(this);
        this.lispXtrSouthboundHandler = lxsbh;
        if (Epoll.isAvailable()) {
            eventLoopGroup = new EpollEventLoopGroup(numChannels, threadFactory);
            channelType = EpollDatagramChannel.class;
            bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
            bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
            LOG.debug("Using Netty Epoll for UDP sockets");
        } else {
            eventLoopGroup = new NioEventLoopGroup(0, threadFactory);
            channelType = NioDatagramChannel.class;
            LOG.debug("Using Netty I/O (non-Epoll) for UDP sockets");
        }
        bootstrap.group(eventLoopGroup);
        bootstrap.channel(channelType);
        bootstrap.handler(lsbh);
        xtrBootstrap.group(eventLoopGroup);
        xtrBootstrap.channel(channelType);
        xtrBootstrap.handler(lxsbh);
        start();
        startXtr();
        clusterSingletonService.registerClusterSingletonService(this);
        LOG.info("LISP (RFC6830) Southbound Plugin is up!");
    }
}
Also used : AuthKeyDb(org.opendaylight.lispflowmapping.mapcache.AuthKeyDb) AuthenticationKeyDataListener(org.opendaylight.lispflowmapping.southbound.lisp.AuthenticationKeyDataListener) DataStoreBackEnd(org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd) LispXtrSouthboundHandler(org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) LispSouthboundHandler(org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler) HashMapDb(org.opendaylight.lispflowmapping.inmemorydb.HashMapDb) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 53 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project netty by netty.

the class EpollSocketChannelBenchmark method setup.

@Setup
public void setup() throws Exception {
    group = new EpollEventLoopGroup(1);
    // add an arbitrary timeout to make the timer reschedule
    future = group.schedule(new Runnable() {

        @Override
        public void run() {
            throw new AssertionError();
        }
    }, 5, TimeUnit.MINUTES);
    serverChan = new ServerBootstrap().channel(EpollServerSocketChannel.class).group(group).childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            ch.pipeline().addLast(new ChannelDuplexHandler() {

                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) {
                    if (msg instanceof ByteBuf) {
                        ctx.writeAndFlush(msg, ctx.voidPromise());
                    } else {
                        throw new AssertionError();
                    }
                }
            });
        }
    }).bind(0).sync().channel();
    chan = new Bootstrap().channel(EpollSocketChannel.class).handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            ch.pipeline().addLast(new ChannelDuplexHandler() {

                private ChannelPromise lastWritePromise;

                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) {
                    if (msg instanceof ByteBuf) {
                        ByteBuf buf = (ByteBuf) msg;
                        try {
                            if (buf.readableBytes() == 1) {
                                lastWritePromise.trySuccess();
                                lastWritePromise = null;
                            } else {
                                throw new AssertionError();
                            }
                        } finally {
                            buf.release();
                        }
                    } else {
                        throw new AssertionError();
                    }
                }

                @Override
                public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                    if (lastWritePromise != null) {
                        throw new IllegalStateException();
                    }
                    lastWritePromise = promise;
                    super.write(ctx, msg, ctx.voidPromise());
                }
            });
        }
    }).group(group).connect(serverChan.localAddress()).sync().channel();
    abyte = chan.alloc().directBuffer(1);
    abyte.writeByte('a');
}
Also used : Channel(io.netty.channel.Channel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) ByteBuf(io.netty.buffer.ByteBuf) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer) Setup(org.openjdk.jmh.annotations.Setup)

Example 54 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project flink by apache.

the class NettyServer method initEpollBootstrap.

private void initEpollBootstrap() {
    // Add the server port number to the name in order to distinguish
    // multiple servers running on the same host.
    String name = NettyConfig.SERVER_THREAD_GROUP_NAME + " (" + config.getServerPort() + ")";
    EpollEventLoopGroup epollGroup = new EpollEventLoopGroup(config.getServerNumThreads(), getNamedThreadFactory(name));
    bootstrap.group(epollGroup).channel(EpollServerSocketChannel.class);
}
Also used : EpollEventLoopGroup(org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup)

Example 55 with EpollEventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollEventLoopGroup in project blade by biezhi.

the class EpollKit method group.

static NettyServerGroup group(int threadCount, int workers) {
    var bossGroup = new EpollEventLoopGroup(threadCount, new NamedThreadFactory("epoll-boss@"));
    var workerGroup = new EpollEventLoopGroup(workers, new NamedThreadFactory("epoll-worker@"));
    return NettyServerGroup.builder().boosGroup(bossGroup).workerGroup(workerGroup).socketChannel(EpollServerSocketChannel.class).build();
}
Also used : EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) lombok.var(lombok.var) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NamedThreadFactory(com.blade.kit.NamedThreadFactory)

Aggregations

EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)56 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)47 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)20 EventLoopGroup (io.netty.channel.EventLoopGroup)19 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)14 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)14 SocketChannel (io.netty.channel.socket.SocketChannel)13 ChannelPipeline (io.netty.channel.ChannelPipeline)12 Channel (io.netty.channel.Channel)10 InetSocketAddress (java.net.InetSocketAddress)10 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)9 IOException (java.io.IOException)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 ChannelFuture (io.netty.channel.ChannelFuture)8 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)8 SslContext (io.netty.handler.ssl.SslContext)8 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)7 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)7 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)6 LoggingHandler (io.netty.handler.logging.LoggingHandler)6