users@grizzly.java.net

Doubts about SelectionKey expire

From: Luiz Hamilton R L Soares <luizhamilton29_at_yahoo.com.br>
Date: Tue, 25 Sep 2007 18:22:48 -0300 (ART)

  Hi,
   
  First of all, thanks for the help about Async TCP Server. I´ve implemented it, but my server was losing performance, so I decided to disable it.
   
  Well, now I have another doubt.
   
  I´m facing some problem with idle connections. I´ve set up timeout to five minutes and it was cancelling one SelectionKey each 5 minutes. And after some time, I have more than 1.000 idle connections and only one is cancelled every 5 minutes.
   
  I looked the source code of DefaultSelectionKeyHandler and I´ve found a method called expire(Iterator<SelectionKey> iterator) . I changed one line:
  nextKeysExpiration = currentTime + timeout;
  to
  nextKeysExpiration = currentTime + 20*1000L;
  Now it tries to cancel a SelectionKey every 20 seconds and my timeout is still 5 minutes.
   
  That was working fine, but after a while, keys that is more than 5 hours idle was not getting cancelled. So I´ve changed another line:
   
  if (currentTime < nextKeysExpiration) {
                return;
  }
   
  to
  if (currentTime < nextKeysExpiration) {
                //return;
  }
   
  I´ve just commented the "return". Now it is cancelling every SelectionKey which is expired.
   
  Well, I´m not sure if I did something wrong. I´m afraid to get another problem after I´ve commented that return. My server is working fine and stable, but I´m not 100% sure if what I did is correct.
   
  Thanks for any help,
   
  Luiz Soares
   
   



       Flickr agora em português. Você clica, todo mundo vê. Saiba mais.