Netty concurrency and "Connection reset by peer"

lotstyl lotstyl at fastwebnet.it
Mon Oct 24 20:13:40 EDT 2011


Hi, I've built the following simple server, and I'm stress testing it using
*ab*.
If I run *ab* making 3000 total request (300 concurrent) it works. If I run
it again, it shows me: 

*apr_socket_connect(): Connection reset by peer (54)*

And If after this error, I try to make a single request with curl without
restarting the server, it works. If I run again *ab* it shows the same
error.

It seems to be that it can't handle too many concurrent connections. Below
the code:

	public static void main(String[] args) throws Exception {

		ServerBootstrap bootstrap = new ServerBootstrap(
				new NioServerSocketChannelFactory(
						Executors.newCachedThreadPool(),
						Executors.newCachedThreadPool()));
		
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

			@Override
			public ChannelPipeline getPipeline() throws Exception {
				return Channels.pipeline(new StringEncoder(), new MyServerHandler());
			}
		});

		bootstrap.bind(new InetSocketAddress(9090));
		System.out.println("Running");
	}


Here is the handler:



public class MyServerHandler extends SimpleChannelUpstreamHandler {

	private static AtomicLong request = new AtomicLong();

	@Override
	public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent
e)
			throws Exception {	
		ChannelFuture channelFuture = e.getChannel().write("This is request #" +
request.incrementAndGet() + "\n");
		channelFuture.addListener(ChannelFutureListener.CLOSE);
	}

	@Override
	public void channelDisconnected(ChannelHandlerContext ctx,
			ChannelStateEvent e) throws Exception {
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			throws Exception {
		System.out.println(e.getCause());
		e.getChannel().close();
	}

}


As you see it's very simple, it just shows the total number of requests
handled.
Any tips?

Thanks


--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Netty-concurrency-and-Connection-reset-by-peer-tp6927082p6927082.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list