title: ElasticSearch consumes 100% CPU
body: <p>After some period of time (sometimes minutes, sometimes days), my app start consuming 100% CPU. As I see from VisualVM, it's always happening at <code>org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink</code> class.</p>
  
  <p>And also, as I see from logs, it throws following exception:</p>
  
  <pre><code>NioClientSocketPipelineSink:internalWarn:105 - Unexpected exception in the selector loop.
  java.nio.channels.CancelledKeyException
      at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)
      at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69)
      at java.nio.channels.SelectionKey.isConnectable(SelectionKey.java:318)
      at org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:369)
      at org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:292)
      at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
      at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>Btw, i'm not sure where is a problem.</p>
  
  <p>Is it ElasticSearch issue? Or embedded Netty? Or my server/app configuration?</p>
  
  <p>I'm using Ubuntu 64 11.10, Sun Java 1.6.0_26-b03 and Elastic Search 0.18.5</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Seems that it was because I've tried to open and close connection for every request to ElasticSearch. And it was, i guess, some kind of concurrency issue.</p>
  
  <p>Fixed by opening a connection to Elastic Search just once, on startup.</p>