Software Qustions
Software Qustions

Reputation: 221

Netty 10000 connections at the same time

I am trying to simulate a 10000 client connection at the same time to server using Netty. When 956 clients connect to the server everything work great, but the 957 client cause an error exception.

Note: I am running the server and the clients at the same machine(win7 8GB ram, i7-CPU)

The error:

java.lang.IllegalStateException: failed to create a child event loop
io.netty.channel.ChannelException: failed to open a new selector

My code:

try {
        con.connect();
    } catch (Exception e) {
        logger.error("Client: error connect to ip {} and port {}, ",id, ip, port,e);
        return;
    }

The code of connect method is:

public void connect() {
    workerGroup = new NioEventLoopGroup();
    Bootstrap bs = new Bootstrap();
    bs.group(workerGroup).channel(NioSocketChannel.class);
    bs.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 300));
            ch.pipeline().addLast("idleStateActionHandler", new IdleStateEventHandler());
            ch.pipeline().addLast("logger", new LoggingHandler());
            ch.pipeline().addLast("commandDecoder", new CommandDecoder());
            ch.pipeline().addLast("commandEncoder", new CommandEncoder());
        }
    });

Upvotes: 2

Views: 1785

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23557

You should use the same NioEventLoopGroup instance for each connect call. Otherwise you will create a lot of Threads.

Upvotes: 6

Related Questions