Search in sources :

Example 51 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project aerospike-client-java by aerospike.

the class SuiteAsync method init.

@BeforeClass
public static void init() {
    System.out.println("Begin AerospikeClient");
    Args args = Args.Instance;
    EventPolicy eventPolicy = new EventPolicy();
    switch(args.eventLoopType) {
        default:
        case DIRECT_NIO:
            {
                eventLoops = new NioEventLoops(eventPolicy, 1);
                break;
            }
        case NETTY_NIO:
            {
                EventLoopGroup group = new NioEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
                break;
            }
        case NETTY_EPOLL:
            {
                EventLoopGroup group = new EpollEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
                break;
            }
        case NETTY_KQUEUE:
            {
                EventLoopGroup group = new KQueueEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
                break;
            }
        case NETTY_IOURING:
            {
                EventLoopGroup group = new IOUringEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, args.eventLoopType);
                break;
            }
    }
    try {
        ClientPolicy policy = new ClientPolicy();
        policy.eventLoops = eventLoops;
        policy.user = args.user;
        policy.password = args.password;
        policy.authMode = args.authMode;
        policy.tlsPolicy = args.tlsPolicy;
        Host[] hosts = Host.parseHosts(args.host, args.port);
        eventLoop = eventLoops.get(0);
        client = new AerospikeClient(policy, hosts);
        try {
            args.setServerSpecific(client);
        } catch (RuntimeException re) {
            client.close();
            throw re;
        }
    } catch (Exception e) {
        eventLoops.close();
        throw e;
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Args(com.aerospike.test.util.Args) ClientPolicy(com.aerospike.client.policy.ClientPolicy) EventPolicy(com.aerospike.client.async.EventPolicy) Host(com.aerospike.client.Host) NioEventLoops(com.aerospike.client.async.NioEventLoops) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BeforeClass(org.junit.BeforeClass)

Example 52 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project riposte by Nike-Inc.

the class StreamingAsyncHttpClient method getPoolMap.

protected ChannelPoolMap<InetSocketAddress, SimpleChannelPool> getPoolMap() {
    ChannelPoolMap<InetSocketAddress, SimpleChannelPool> result = poolMap;
    if (poolMap == null) {
        /*
                This method gets called for every downstream call, so we don't want to synchronize the whole method. But
                it's easy for multiple threads to get here at the same time when the server starts up, so we need *some*
                kind of protection around the creation of poolMap, hence the elaborate (but correct) double-checked
                locking. Since poolMap is volatile this works, and the local variable "result" helps with speed during
                the normal case where poolMap has already been initialized.
                See https://en.wikipedia.org/wiki/Double-checked_locking
             */
        synchronized (this) {
            result = poolMap;
            if (result == null) {
                EventLoopGroup eventLoopGroup;
                Class<? extends SocketChannel> channelClass;
                if (Epoll.isAvailable()) {
                    logger.info("Creating channel pool. The epoll native transport is available. Using epoll instead of " + "NIO. proxy_router_using_native_epoll_transport=true");
                    eventLoopGroup = new EpollEventLoopGroup(0, createProxyRouterThreadFactory());
                    channelClass = EpollSocketChannel.class;
                } else {
                    logger.info("Creating channel pool. The epoll native transport is NOT available or you are not running " + "on a compatible OS/architecture. Using NIO. " + "proxy_router_using_native_epoll_transport=false");
                    eventLoopGroup = new NioEventLoopGroup(0, createProxyRouterThreadFactory());
                    channelClass = NioSocketChannel.class;
                }
                result = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {

                    @Override
                    protected SimpleChannelPool newPool(InetSocketAddress key) {
                        return new SimpleChannelPool(generateClientBootstrap(eventLoopGroup, channelClass).remoteAddress(key), new ChannelPoolHandlerImpl(), CHANNEL_HEALTH_CHECK_INSTANCE) {

                            @Override
                            public Future<Void> release(Channel channel, Promise<Void> promise) {
                                markChannelBrokenAndLogInfoIfHttpClientCodecStateIsNotZero(channel, "Releasing channel back to pool");
                                return super.release(channel, promise);
                            }

                            @Override
                            protected Channel pollChannel() {
                                Channel channel = super.pollChannel();
                                if (channel != null) {
                                    markChannelBrokenAndLogInfoIfHttpClientCodecStateIsNotZero(channel, "Polling channel to be reused before healthcheck");
                                    if (idleChannelTimeoutMillis > 0) {
                                        /*
                                             We have a channel that is about to be re-used, so disable the idle channel
                                             timeout detector if it exists. By disabling it here we make sure that it is
                                             effectively "gone" before the healthcheck happens, preventing race
                                             conditions. Note that we can't call pipeline.remove() here because we may
                                             not be in the pipeline's event loop, so calling pipeline.remove() could
                                             lead to thread deadlock, but we can't call channel.eventLoop().execute()
                                             because we need it disabled *now* before the healthcheck happens. The
                                             pipeline preparation phase will remove it safely soon, and in the meantime
                                             it will be disabled.
                                             */
                                        ChannelPipeline pipeline = channel.pipeline();
                                        ChannelHandler idleHandler = pipeline.get(DOWNSTREAM_IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
                                        if (idleHandler != null) {
                                            ((DownstreamIdleChannelTimeoutHandler) idleHandler).disableTimeoutHandling();
                                        }
                                    }
                                }
                                return channel;
                            }

                            @Override
                            protected boolean offerChannel(Channel channel) {
                                if (idleChannelTimeoutMillis > 0) {
                                    // Add an idle channel timeout detector. This will be removed before the
                                    // channel's reacquisition healthcheck runs (in pollChannel()), so we won't
                                    // have a race condition where this channel is handed over for use but gets
                                    // squashed right before it's about to be used.
                                    // NOTE: Due to the semantics of pool.release() we're guaranteed to be in the
                                    // channel's event loop, so there's no chance of a thread deadlock when
                                    // messing with the pipeline.
                                    channel.pipeline().addFirst(DOWNSTREAM_IDLE_CHANNEL_TIMEOUT_HANDLER_NAME, new DownstreamIdleChannelTimeoutHandler(idleChannelTimeoutMillis, () -> true, false, "StreamingAsyncHttpClientChannel-idle", null, null));
                                }
                                return super.offerChannel(channel);
                            }
                        };
                    }
                };
                poolMap = result;
            }
        }
    }
    return result;
}
Also used : DownstreamIdleChannelTimeoutHandler(com.nike.riposte.client.asynchttp.netty.downstreampipeline.DownstreamIdleChannelTimeoutHandler) InetSocketAddress(java.net.InetSocketAddress) SocketChannel(io.netty.channel.socket.SocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) Channel(io.netty.channel.Channel) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) CompletableFuture(java.util.concurrent.CompletableFuture) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) SimpleChannelPool(io.netty.channel.pool.SimpleChannelPool) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 53 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.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 54 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.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 55 with EpollEventLoopGroup

use of org.apache.beam.vendor.grpc.v1p43p2.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)

Aggregations

EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)55 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)46 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 LoggingHandler (io.netty.handler.logging.LoggingHandler)6 SslHandler (io.netty.handler.ssl.SslHandler)6