selector.select() in NIO and high cpu usage

Discussion in 'Java' started by Arandil, Apr 12, 2004.

  1. Arandil

    Arandil Guest

    Hello,

    I have a 'little' problem with Selector.select() method. I was using NIO in
    my app successfully till the time I had to connect to about 50 hosts
    simulateously... Everything works, but every thread I use to wait for data
    from remote host is using very much CPU (even when no data is being transfered).
    I used profiler to find out which method is faulty. I found out, that my problem
    is in Selector.select() method. It is taking almost all available CPU power,
    no matter if there is any data waiting...

    Is there any way to reduce the CPU load to the minimum or do I have to use
    other method than Selectors?

    Thanks in advance and best regards,
    Arandil.

    --
    whitestok.no-ip.com - Whitestok DC Hub / bigbass.no-ip.com - BigBass DC Hub
    BinPost v0.4 beta - http://binpost.prv.pl - poster binariów mojego autorstwa
    "A little time to make up our minds
    A little time to fill up our dreams" Helloween - A Little Time
    Arandil, Apr 12, 2004
    #1
    1. Advertising

  2. Arandil

    Arandil Guest

    W po¶cie <>, Arandil wyciapcia³:

    > Is there any way to reduce the CPU load to the minimum or do I have to use
    > other method than Selectors?


    Mea culpa, my fault... Profiler did say that select() was taking whole CPU load,
    but that's not true... Indeed, there was a loop, but it was caused by my
    overlooking of the problem - I had a loop, which was appending every bytebuffer
    into one byte array (when there were more than one). It was looping, when
    read() function didn't return 0. And this is the fault - n != 0, not n > 0...
    Forgot about -1 (end of stream) :/

    Sorry for garbage, and not cancelling to get this post to google - maybe
    someone will need it one day...

    Best regards, Arandil.

    --
    whitestok.no-ip.com - Whitestok DC Hub / bigbass.no-ip.com - BigBass DC Hub
    BinPost v0.4 beta - http://binpost.prv.pl - poster binariów mojego autorstwa
    "A little time to make up our minds
    A little time to fill up our dreams" Helloween - A Little Time
    Arandil, Apr 12, 2004
    #2
    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. mk
    Replies:
    1
    Views:
    10,325
    Robert Olofsson
    Jul 25, 2003
  2. Peter Carter
    Replies:
    1
    Views:
    2,888
    Bill Scott
    Apr 12, 2004
  3. rajatag
    Replies:
    6
    Views:
    595
    rajatag
    Feb 1, 2006
  4. Jerry L. Gubka

    Web Page = High CPU Usage?

    Jerry L. Gubka, Jan 3, 2004, in forum: HTML
    Replies:
    2
    Views:
    774
  5. Domagoj Klepac

    NIO - Selector.select() doesn't block

    Domagoj Klepac, May 7, 2006, in forum: Java
    Replies:
    7
    Views:
    6,348
    Gordon Beaton
    May 10, 2006
Loading...

Share This Page