BindingException after trying to bind 28231 client connections

Tim McCauley nettytim at gmail.com
Wed Nov 24 20:55:31 EST 2010


I am rather new to Netty and having some issues trying to create
multiple connections to a server to test it using the same
ClientBootstrap and trying to connect to the same host and port.

I am trying to create over 60,000 client connections from one box
running Ubuntu 10.4 to a server also running Ubunto 10.4 server that
are connected on the same subnet.  The protocol is RESTful and the
client once connected must stay connected because of Https and having
to send data to the server every 100 seconds.

In instantiating the clients I use the same basic approach that was
taken in the bench mark client and that is in a loop over a number of
connections to create then with the ClientBootstrap connect to the
host and port of the server.  This all works good until I hit the
28231 connection.  The code I am using is below.  Should I be creating
asynchronous client connections in the way or is there a better
approach?

By the way I running sudo and setting

ulimit -n 70000

so that the process can open 70000 files.

After the 28231 client connection to the same host and port I get the
following exception:

 java.net.BindException: Cannot assign requested address
        at sun.nio.ch.Net.connect(Native Method) ~[na:1.6.0_22]
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:507)
~[na:1.6.0_
22]
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioCl
ientSocketPipelineSink.java:140) ~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:103)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.handler.codec.http.HttpClientCodec.handleDownstream(HttpClientCodec.java:82)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.channel.Channels.connect(Channels.java:541)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
~[jar:rsrc:netty-3.2.3.Final.jar!/:na]
        at com.cisco.sse.femto.cmhs.client.MultiSTUN_HeartbeatHttpClient.createConnectionsToServer(MultiSTUN_HeartbeatHttpClient.java:147)
[rsrc:./:na]
        at com.cisco.sse.femto.cmhs.client.MultiSTUN_HeartbeatHttpClient.main(MultiSTUN_HeartbeatHttpClient.java:115)
[rsrc:./:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:1.6.0_22]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
~[na:1.6.0_22]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
~[na:1.6.0_22]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_22]
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
[cmhs_client.jar:na]


bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
		Executors.newCachedThreadPool(),
		Executors.newCachedThreadPool()));

// Set up the event pipeline factory.
bootstrap.setPipelineFactory(new HttpSTUN_HeartbeatClientPipelineFactory(
		uri, numHeartbeats, connClosed));

 private void createConnectionsToServer() {

   fa = new ChannelFuture[numConn];
   int t = 0;
   for (int i = 0; i < numConn; i++) {
      fa[i] = bootstrap.connect(new InetSocketAddress(host, port));
      fa[i].awaitUninterruptibly();
      if(!fa[i].isSuccess()) {
         log.error("Channel unsuccessful at connecting to server. ",
fa[i].getCause());
         if(t < 5) {
            i--;
            log.debug("Try {}", i);
            t++;
            try {
               Thread.sleep(200);
            } catch (InterruptedException e) {
	// do nothing
            }
         } else {
            log.error("Shutting down the client.");
            System.exit(0);
         }

      } else {
         log.debug("Connected client {}", i);
         t = 0;
         cg.add(fa[i].getChannel());
      }
   }
}



More information about the netty-users mailing list