Example usage for io.netty.channel.epoll EpollChannelOption TCP_CORK

List of usage examples for io.netty.channel.epoll EpollChannelOption TCP_CORK

Introduction

In this page you can find the example usage for io.netty.channel.epoll EpollChannelOption TCP_CORK.

Prototype

ChannelOption TCP_CORK

To view the source code for io.netty.channel.epoll EpollChannelOption TCP_CORK.

Click Source Link

Usage

From source file:io.blobkeeper.server.BlobKeeperServer.java

License:Apache License

@Override
protected void doStart() {
    fileWriterService.start();/*from ww  w  . j a va  2  s  .  c o  m*/
    clusterMembershipService.start(serverConfiguration.getServerName());

    bossGroup = new EpollEventLoopGroup();
    // FIXME: add to config
    workerGroup = new EpollEventLoopGroup(512);

    bootstrap = new ServerBootstrap();
    bootstrap.option(ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    bootstrap.group(bossGroup, workerGroup).channel(EpollServerSocketChannel.class)
            .childHandler(serverInitializer);

    bootstrap.childOption(SO_LINGER, -1);
    bootstrap.childOption(TCP_NODELAY, true);
    bootstrap.childOption(SO_REUSEADDR, true);
    bootstrap.childOption(ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    bootstrap.childOption(EpollChannelOption.SO_REUSEPORT, true);
    bootstrap.childOption(EpollChannelOption.TCP_CORK, true);

    try {
        serverChannel = bootstrap.bind(serverConfiguration.getServerPort()).sync();
        notifyStarted();
    } catch (InterruptedException e) {
        notifyFailed(e);
        throw new RuntimeException(e);
    }
}

From source file:io.maelstorm.server.ServerInit.java

License:Open Source License

public void start(String configFile, RequestHandler handler) throws Exception {
    LOG.info("Starting.");
    AppendableCharSequenceAddon.configure();
    try {/*from  w  w  w .j  a  v a2 s .co m*/
        System.in.close(); // Release a FD we don't need.
    } catch (Exception e) {
        LOG.warn("Failed to close stdin", e);
    }
    Properties prop = getProperties(configFile);
    requestDistributor = handler;
    requestDistributor.setInitializer(this);
    String os = System.getProperty("os.name").toLowerCase(Locale.UK).trim();
    if (os.startsWith("linux")) {
        bossGroup = (null == bossGroup) ? new EpollEventLoopGroup(1) : bossGroup;
        workerGroup = (null == workerGroup) ? new EpollEventLoopGroup(NUM_WORKER_THREADS) : workerGroup;
    } else {
        bossGroup = (null == bossGroup) ? new NioEventLoopGroup(1) : bossGroup;
        workerGroup = (null == workerGroup) ? new NioEventLoopGroup(NUM_WORKER_THREADS) : workerGroup;
    }

    String[] servers = prop.getProperty("servers").split(",");
    for (String server : servers) {

        try {
            controller = new ServerBootstrap();
            controller.group(bossGroup, workerGroup);
            if (os.startsWith("linux")) {
                controller.channel(EpollServerSocketChannel.class);
                controller.option(EpollChannelOption.TCP_CORK, true);
            } else {
                controller.channel(NioServerSocketChannel.class);
            }
            controller.childHandler(new PipelineFactory(handler, getPipelineConfig(prop, server)));
            controller.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
            controller.option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT);
            controller.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
                    getInt(prop, server, "connectTimeoutMillis"));
            controller.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 64 * 1024);
            controller.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1 * 1024);
            controller.option(ChannelOption.SO_KEEPALIVE, getBoolean(prop, server, "SOKeepalive"));
            controller.option(ChannelOption.SO_REUSEADDR, true);
            controller.option(ChannelOption.TCP_NODELAY, true);
            controller.option(ChannelOption.SO_LINGER, 0);
            controller.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
            controller.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 64 * 1024);
            controller.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 10);
            controller.childOption(ChannelOption.SO_KEEPALIVE, true);
            controller.childOption(ChannelOption.SO_REUSEADDR, true);
            controller.childOption(ChannelOption.TCP_NODELAY, true);
            controller.childOption(ChannelOption.SO_LINGER, 0);
            controller.childOption(ChannelOption.SO_RCVBUF, 6291456);

            final InetSocketAddress addr = new InetSocketAddress(getInt(prop, server, "port"));
            ChannelFuture future = controller.bind(addr).sync();
            if (future.isSuccess())
                LOG.info("Server Ready to serve on " + addr);
            else
                throw new Exception("Address already in use");
        } catch (Throwable t) {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
            throw new RuntimeException("Initialization failed", t);
        }
    }
}

From source file:io.nebo.container.NettyEmbeddedServletContainer.java

License:Apache License

private void groups(ServerBootstrap b) {
    if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
        b.channel(EpollServerSocketChannel.class).group(bossGroup, workerGroup)
                .option(EpollChannelOption.TCP_CORK, true);
    } else {//from   ww  w.  jav a  2s .com
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
        b.channel(NioServerSocketChannel.class).group(bossGroup, workerGroup);
    }
    b.option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.SO_BACKLOG, 100);
    logger.info("Bootstrap configuration: " + b.toString());
}

From source file:io.vertx.core.net.impl.transport.EpollTransport.java

License:Open Source License

@Override
public void configure(NetServerOptions options, ServerBootstrap bootstrap) {
    bootstrap.option(EpollChannelOption.SO_REUSEPORT, options.isReusePort());
    if (options.isTcpFastOpen()) {
        bootstrap.option(EpollChannelOption.TCP_FASTOPEN,
                options.isTcpFastOpen() ? pendingFastOpenRequestsThreshold : 0);
    }/*from w w  w . j  a  va2  s  .com*/
    bootstrap.childOption(EpollChannelOption.TCP_QUICKACK, options.isTcpQuickAck());
    bootstrap.childOption(EpollChannelOption.TCP_CORK, options.isTcpCork());
    super.configure(options, bootstrap);
}

From source file:io.vertx.core.net.impl.transport.EpollTransport.java

License:Open Source License

@Override
public void configure(ClientOptionsBase options, Bootstrap bootstrap) {
    if (options.isTcpFastOpen()) {
        bootstrap.option(EpollChannelOption.TCP_FASTOPEN_CONNECT, options.isTcpFastOpen());
    }// w w  w . j  a v  a2 s  .  co m
    bootstrap.option(EpollChannelOption.TCP_QUICKACK, options.isTcpQuickAck());
    bootstrap.option(EpollChannelOption.TCP_CORK, options.isTcpCork());
    super.configure(options, bootstrap);
}

From source file:singh.jatinder.client.Client.java

License:Open Source License

public void init() {
    String os = System.getProperty("os.name").toLowerCase(Locale.UK).trim();
    if (os.startsWith("linux")) {
        group = (null == group) ? new EpollEventLoopGroup(1) : group;
    } else {//from  w  ww. j av  a 2  s.  co  m
        group = (null == group) ? new NioEventLoopGroup(1) : group;
    }

    try {
        // Configure the client.
        controller = new Bootstrap();
        controller.group(group);
        if (os.startsWith("linux")) {
            controller.channel(EpollSocketChannel.class);
            controller.option(EpollChannelOption.TCP_CORK, true);
        } else {
            controller.channel(NioSocketChannel.class);
        }
        controller.handler(new PipelineFactory(null));
    } catch (Throwable t) {
        group.shutdownGracefully();
        throw new RuntimeException("Initialization failed", t);
    }
}