• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

possible causes for CPU spike

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,

I'll try thread dump
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Peter indicated, it might help if you showed us your code for those loops.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic