Search in sources :

Example 1 with EpollEventLoopGroup

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

the class NettyClient method initEpollBootstrap.

private void initEpollBootstrap() {
    // Add the server port number to the name in order to distinguish
    // multiple clients running on the same host.
    String name = NettyConfig.CLIENT_THREAD_GROUP_NAME + " (" + config.getServerPort() + ")";
    EpollEventLoopGroup epollGroup = new EpollEventLoopGroup(config.getClientNumThreads(), NettyServer.getNamedThreadFactory(name));
    bootstrap.group(epollGroup).channel(EpollSocketChannel.class);
}
Also used : EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup)

Example 2 with EpollEventLoopGroup

use of io.netty.channel.epoll.EpollEventLoopGroup in project netty-socketio by mrniko.

the class SocketIOServer method initGroups.

protected void initGroups() {
    if (configCopy.isUseLinuxNativeEpoll()) {
        bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads());
        workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads());
    } else {
        bossGroup = new NioEventLoopGroup(configCopy.getBossThreads());
        workerGroup = new NioEventLoopGroup(configCopy.getWorkerThreads());
    }
}
Also used : EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 3 with EpollEventLoopGroup

use of io.netty.channel.epoll.EpollEventLoopGroup in project cassandra by apache.

the class NativeTransportService method initialize.

/**
     * Creates netty thread pools and event loops.
     */
@VisibleForTesting
synchronized void initialize() {
    if (initialized)
        return;
    // prepare netty resources
    eventExecutorGroup = new RequestThreadPoolExecutor();
    if (useEpoll()) {
        workerGroup = new EpollEventLoopGroup();
        logger.info("Netty using native Epoll event loop");
    } else {
        workerGroup = new NioEventLoopGroup();
        logger.info("Netty using Java NIO event loop");
    }
    int nativePort = DatabaseDescriptor.getNativeTransportPort();
    int nativePortSSL = DatabaseDescriptor.getNativeTransportPortSSL();
    InetAddress nativeAddr = DatabaseDescriptor.getRpcAddress();
    org.apache.cassandra.transport.Server.Builder builder = new org.apache.cassandra.transport.Server.Builder().withEventExecutor(eventExecutorGroup).withEventLoopGroup(workerGroup).withHost(nativeAddr);
    if (!DatabaseDescriptor.getClientEncryptionOptions().enabled) {
        servers = Collections.singleton(builder.withSSL(false).withPort(nativePort).build());
    } else {
        if (nativePort != nativePortSSL) {
            // user asked for dedicated ssl port for supporting both non-ssl and ssl connections
            servers = Collections.unmodifiableList(Arrays.asList(builder.withSSL(false).withPort(nativePort).build(), builder.withSSL(true).withPort(nativePortSSL).build()));
        } else {
            // ssl only mode using configured native port
            servers = Collections.singleton(builder.withSSL(true).withPort(nativePort).build());
        }
    }
    // register metrics
    ClientMetrics.instance.addCounter("connectedNativeClients", () -> {
        int ret = 0;
        for (Server server : servers) ret += server.getConnectedClients();
        return ret;
    });
    AuthMetrics.init();
    initialized = true;
}
Also used : RequestThreadPoolExecutor(org.apache.cassandra.transport.RequestThreadPoolExecutor) Server(org.apache.cassandra.transport.Server) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with EpollEventLoopGroup

use of io.netty.channel.epoll.EpollEventLoopGroup in project grpc-java by grpc.

the class Utils method newNettyClientChannel.

private static NettyChannelBuilder newNettyClientChannel(Transport transport, SocketAddress address, boolean tls, boolean testca, int flowControlWindow, boolean useDefaultCiphers) throws IOException {
    NettyChannelBuilder builder = NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow);
    if (tls) {
        builder.negotiationType(NegotiationType.TLS);
        SslContext sslContext = null;
        if (testca) {
            File cert = TestUtils.loadCert("ca.pem");
            SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient().trustManager(cert);
            if (transport == Transport.NETTY_NIO) {
                sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.JDK);
            } else {
                // Native transport with OpenSSL
                sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.OPENSSL);
            }
            if (useDefaultCiphers) {
                sslContextBuilder.ciphers(null);
            }
            sslContext = sslContextBuilder.build();
        }
        builder.sslContext(sslContext);
    } else {
        builder.negotiationType(NegotiationType.PLAINTEXT);
    }
    DefaultThreadFactory tf = new DefaultThreadFactory("client-elg-", true);
    switch(transport) {
        case NETTY_NIO:
            builder.eventLoopGroup(new NioEventLoopGroup(0, tf)).channelType(NioSocketChannel.class);
            break;
        case NETTY_EPOLL:
            // These classes only work on Linux.
            builder.eventLoopGroup(new EpollEventLoopGroup(0, tf)).channelType(EpollSocketChannel.class);
            break;
        case NETTY_UNIX_DOMAIN_SOCKET:
            // These classes only work on Linux.
            builder.eventLoopGroup(new EpollEventLoopGroup(0, tf)).channelType(EpollDomainSocketChannel.class);
            break;
        default:
            // Should never get here.
            throw new IllegalArgumentException("Unsupported transport: " + transport);
    }
    return builder;
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) File(java.io.File) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext)

Example 5 with EpollEventLoopGroup

use of io.netty.channel.epoll.EpollEventLoopGroup in project pulsar by yahoo.

the class PulsarClientImpl method getEventLoopGroup.

private static EventLoopGroup getEventLoopGroup(ClientConfiguration conf) {
    int numThreads = conf.getIoThreads();
    ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io");
    if (SystemUtils.IS_OS_LINUX) {
        try {
            return new EpollEventLoopGroup(numThreads, threadFactory);
        } catch (ExceptionInInitializerError | NoClassDefFoundError | UnsatisfiedLinkError e) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to load EpollEventLoop", e);
            }
            return new NioEventLoopGroup(numThreads, threadFactory);
        }
    } else {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)16 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)12 EventLoopGroup (io.netty.channel.EventLoopGroup)8 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)4 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)4 AerospikeClient (com.aerospike.client.AerospikeClient)3 NettyEventLoops (com.aerospike.client.async.NettyEventLoops)3 NioEventLoops (com.aerospike.client.async.NioEventLoops)3 SocketChannel (io.netty.channel.socket.SocketChannel)3 Host (com.aerospike.client.Host)2 ClientPolicy (com.aerospike.client.policy.ClientPolicy)2 JCommander (com.beust.jcommander.JCommander)2 ParameterException (com.beust.jcommander.ParameterException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)2 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)2 PulsarClient (com.yahoo.pulsar.client.api.PulsarClient)2 PulsarClientImpl (com.yahoo.pulsar.client.impl.PulsarClientImpl)2 AdaptiveRecvByteBufAllocator (io.netty.channel.AdaptiveRecvByteBufAllocator)2