Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

possible causes for CPU spike

 
Ishita Saha
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've a piece of code which is reading data from sockets and all that stuff, it also uses infinite loops for the purpose of reading data. While running the code under load - i see a cpu usage of 100%.

request you to please mention some common possible causes of CPU spiking in java code.

Thanks
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
100% CPU load is not necessarily wrong. In a mathematical computation program, for instance, you positively want the CPU to spend all its spare time doing your big computation.

People running things like Web servers generally do use average CPU load as one measure of how stressed the server is. A Web server generally would not be expected to run at 100% CPU load for long periods.

In your application, you are reading data from sockets. Usually, such a program is "I/O-bound". That is, it should use little CPU, because most of its time is spent in a blocked state, waiting for data from the socket.

You say you have infinite loops. Infinite loops will cause 100% CPU utilisation in a single-CPU single-core system, if there are no blocking operations in the loop. You haven't told us much about your loops, so I can't say if they are expected to use 100% CPU.
 
rajesh bala
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a thread dump and look at the threads. It might give a clear picture on where the CPU is spending most of the time. Please note that this is at very very high level and based on its output, you may want to profile the application.

If you are using windows, try ctrl+page-break button to get the threaddump.
If you are using linux, try kill -QUIT <java_pid> to get the threaddump in the console.

All the best.

~Rajesh.B
 
Ishita Saha
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,

I'll try thread dump
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Peter indicated, it might help if you showed us your code for those loops.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic