Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Non Blocking Server - High CPU Usage

Thread view: 
rajatag - 01 Feb 2006 11:20 GMT
Hello,

I was trying out the source code from

http://www.owlmountain.com/tutorials/NonBlockingIo.htm#_Toc524339534

It so happens that CPU Usage becomes 100% even if a single client is
connected to the server. It stays at 100% until all clients disconnect.

Is this normal? Server has been tested on Windows 2003 and XP.

Thanks!
Gordon Beaton - 01 Feb 2006 11:58 GMT
> I was trying out the source code from
>
[quoted text clipped - 3 lines]
> connected to the server. It stays at 100% until all clients
> disconnect.

I haven't tested the code, but I'll guess the problem is due to the
fact that they register interest in OP_WRITE for every connection.
Remove that and see if the problem goes away.

Normally a connection is writeable until write() fails. It's only then
you should register OP_WRITE, and then only until the connection
becomes writeable again.

There was a thread about this here recently, "NIO busywaiting".

/gordon

Signature

[  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

Remon van Vliet - 01 Feb 2006 12:37 GMT
>> I was trying out the source code from
>>
[quoted text clipped - 15 lines]
>
> /gordon

It's either the issue mentioned above or you using selectNow instead of
select. There are only two points in time where you want to register for
OP_WRITE namely after a connect/accept (using it as a notification for when
writing is possible) and when a write initially failed so you can try again
once OP_WRITE is selected. At all other times writing should be valid.

Remon van Vliet
rajatag - 01 Feb 2006 16:46 GMT
Thanks for the replies. I'll test these out and get back on this
thread.
rajatag - 01 Feb 2006 16:52 GMT
Another issue that just came to my mind ... if a write fails and I then
register interest in OP_WRITE, it means that the message that was
supposed to be sent in the failed attempt should be buffered by me?
Gordon Beaton - 01 Feb 2006 17:53 GMT
> Another issue that just came to my mind ... if a write fails and I then
> register interest in OP_WRITE, it means that the message that was
> supposed to be sent in the failed attempt should be buffered by me?

If write fails, then it's completely up to you to deal with it,
including buffering the message in order to try again later if that's
what you want to do.

/gordon

Signature

[  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

rajatag - 01 Feb 2006 17:55 GMT
thanks gordon,

also i have tried removing the OP_WRITE and it works great. CPU usage
is no longer 100%

Thank you so much!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.