Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > NIO CPU Anomaly

Reply
Thread Tools

NIO CPU Anomaly

 
 
JSParker1@hotmail.co.uk
Guest
Posts: n/a
 
      12-14-2004
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      12-14-2004
On 14 Dec 2004 03:35:29 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      12-16-2004
On 14 Dec 2004 22:41:28 +0100, Gordon Beaton <(E-Mail Removed)> 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.
 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      12-17-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlan Hopping Anomaly Jos_Cit Cisco 15 08-15-2005 05:35 AM
NIO with timeouts != NIO? iksrazal Java 1 06-18-2004 02:28 PM
java.NIO + select + Network Interface Down = 100% CPU Usage Peter Carter Java 1 04-12-2004 06:20 PM
selector.select() in NIO and high cpu usage Arandil Java 1 04-12-2004 02:04 PM
Help Needed Java NIO server and Tomcat 100% CPU utilization !!!! Avizz Java 1 12-10-2003 06:38 AM



Advertisments