title: Highly concurrent HTTP with Netty and NIO
body: <p>I am working through the <a href="http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/http/snoop/package-summary.html" rel="noreferrer">example Netty HTTP Client code</a> in order to make http requests within a concurrent, threaded environment. </p>
  
  <p>However, my system breaks completely (with a slew of exceptions) at fairly low throughput.</p>
  
  <p>In almost pseudo-code:</p>
  
  <pre><code>ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory()) 
  bootstrap.setPipelineFactory(new HttpClientPipelineFactory());
  
  ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
  Channel channel = future.awaitUninterruptibly().getChannel();
  
  HttpRequest request = new DefaultHttpRequest();
  channel.write(request);
  </code></pre>
  
  <p>In the example, to make a request I create a ClientBootstrap, and from there (through a few hoops) a Channel to write the HTTPRequest.</p>
  
  <p>This all works and is good. </p>
  
  <p>However, in a concurrent situation, should every request be going through the same hoops? I think that is what's breaking things for me at the moment. Should I be reusing the connection or structuring my client in an entirely different way?</p>
  
  <p>Also: I am doing this in Clojure, if that makes any difference at all. </p>