NIO CPU Anomaly

Discussion in 'Java' started by JSParker1@hotmail.co.uk, Dec 14, 2004.

  1. Guest

    I have recently run into an anomaly using the NIO packages in a
    multithread thick client. Can anybody help?
    The app opens a few of IP connection (about 20) for two way
    communication. It was recently migrated across to use the NIO API and
    this has caused the client CPU to hit 100% even when idle. On the old
    IO packages this was <1% CPU.
    (This is my first newsgroup posting so please let me know if I should
    include more/less info).


    Nick
    , Dec 14, 2004
    #1
    1. Advertising

  2. On 14 Dec 2004 03:35:29 -0800, wrote:
    > I have recently run into an anomaly using the NIO packages in a
    > multithread thick client. Can anybody help?
    >
    > The app opens a few of IP connection (about 20) for two way
    > communication. It was recently migrated across to use the NIO API
    > and this has caused the client CPU to hit 100% even when idle. On
    > the old IO packages this was <1% CPU.
    >
    > (This is my first newsgroup posting so please let me know if I should
    > include more/less info).


    Well, generally you should post a relevant section of code, ideally
    something short that compiles and has the problem you describe.

    However I suspect that you need to remove the SelectionKey from the
    selection Set, or select() will immediately return the same key again
    (even though it might not be ready). Something like this:

    SelectionKey sk;

    Set ready = s.selectedKeys();
    Iterator i = ready.iterator();

    while (i.hasNext()) {
    sk = (SelectionKey)i.next();
    i.remove(); // do this!

    if (sk.isAcceptable()) {
    // accept incoming connection
    }
    else if (sk.isReadable()) {
    // read from SocketChannel
    }
    // etc
    }

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 14, 2004
    #2
    1. Advertising

  3. On 14 Dec 2004 22:41:28 +0100, Gordon Beaton <> wrote:

    > Well, generally you should post a relevant section of code, ideally
    > something short that compiles and has the problem you describe.
    >
    > However I suspect that you need to remove the SelectionKey from the
    > selection Set, or select() will immediately return the same key again
    > (even though it might not be ready). Something like this:
    > /gordon


    Another thing that comes to mind is that you might have switched some
    Channel to non-blocking IO, and read it as if it was blocking, which
    results in hundreds of read-calls all returning no new data.



    --

    Whom the gods wish to destroy they first call promising.
    Stefan Schulz, Dec 16, 2004
    #3
  4. Esmond Pitt Guest

    You should also generally *not* select on OP_WRITE unless you have just
    encountered a short write, as sockets are almost always writable and
    this will cause select() to return immediately.
    Esmond Pitt, Dec 17, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Avizz
    Replies:
    1
    Views:
    4,412
  2. Peter Carter
    Replies:
    1
    Views:
    2,888
    Bill Scott
    Apr 12, 2004
  3. Arandil
    Replies:
    1
    Views:
    1,297
    Arandil
    Apr 12, 2004
  4. iksrazal

    NIO with timeouts != NIO?

    iksrazal, Jun 17, 2004, in forum: Java
    Replies:
    1
    Views:
    6,229
    iksrazal
    Jun 18, 2004
  5. pavunkumar

    How , system cpu and user cpu times calculates

    pavunkumar, Feb 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    338
Loading...

Share This Page