Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: cpu usage?
PostPosted: Mon Oct 24, 2011 2:01 am 
Offline
Senior Newbie

Joined: Sun Oct 23, 2011 4:18 pm
Posts: 6
Hello,

I have been running a java program on my vps and i noticed its always using 100% cpu. Is this normal? I know when I run this java program on my personal windows computer it doesn't take any cpu. My java program is just a basic program that waits for incoming connections and packets for a networked game, even when just sitting there waiting it takes 100% cpu.

*also separate question, top is the best way to check cpu right, ps -ef just shows an average?


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 5:32 am 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
And your incoming loop is e/poll based (blocking on accept)?


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 1:17 pm 
Offline
Senior Newbie

Joined: Sun Oct 23, 2011 4:18 pm
Posts: 6
yes there is a ServerSocket blocking on accept and also a DatagramSocket blocking on receive. I also have a bufferedreader reading incoming line from System.in.

Is it better to not block and to just check every certain amoutn of ms?


Top
   
 Post subject: Re: cpu usage?
PostPosted: Mon Oct 24, 2011 2:41 pm 
Offline
Senior Member
User avatar

Joined: Thu Jun 16, 2011 8:24 am
Posts: 412
Location: Cyberspace
disastorm wrote:
*also separate question, top is the best way to check cpu right, ps -ef just shows an average?


Not being familiar with java, I can't help with your problem, but top is the best if you need to keep a real-time check on your CPU and memory usage. If you need a "snapshot" of the current usage, you can use "ps aux" (no quotes). That will spit out a list of all running processes, and their CPU and memory. That's good for if you need to post it here (make sure to post it as code using the code button above where you type your post).

_________________
Kris the Piki Geeker


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 3:09 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
disastorm wrote:
yes there is a ServerSocket blocking on accept and also a DatagramSocket blocking on receive. I also have a bufferedreader reading incoming line from System.in.

Is it better to not block and to just check every certain amoutn of ms?


Blocking or not depends on the architecture of your application, but I meant are you using e/poll or are you having a loop that constantly checks for data, AFTER the accept?


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 6:21 pm 
Offline
Senior Newbie

Joined: Sun Oct 23, 2011 4:18 pm
Posts: 6
i dont know what e/poll is. it blocks on the actual receive/accept method call. It is also in a loop, but that only occurs once a connection or packet has been received it will then create a new thread and then continue waiting.

The new thread will continue to be in a loop that waits for incoming packets, however, the 100% cpu usage is even when there is no one connected or connecting.


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 7:03 pm 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
First, it's not normal.

Look into setting up JMX debugging and run an environment that let's you remotely debug like Eclipse.


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 7:14 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
Sorry, I don't know then.

But regardless of this issue, check out the Java.nio polling for better performance. The idea is to check for new data and sit and wait at the kernel level until there's something to read, not in the application loop.


Top
   
 Post subject:
PostPosted: Mon Oct 24, 2011 9:37 pm 
Offline
Senior Newbie

Joined: Sun Oct 23, 2011 4:18 pm
Posts: 6
Hello, I just discovered that if I run my java jar file normally, it takes 0 cpu. It only takes 100 when i use it with nohup and ampersand at the end. However, I discovered that instead of using nohup, I can use a "screen" to keep it running when I log out, and it takes only 0 cpu. Is this normal, does nohup make the cpu go crazy for some reason?


Top
   
 Post subject:
PostPosted: Thu Oct 27, 2011 1:21 am 
Offline
Senior Newbie

Joined: Tue Aug 23, 2011 8:08 pm
Posts: 6
Website: http://www.august.com.au/
Location: Australia
disastorm wrote:
Is this normal, does nohup make the cpu go crazy for some reason?


No, nohup doesn't make the CPU go crazy. But nohup does redirect standard input to /dev/null and standard output to 'nohup.out'.

disastorm wrote:
I also have a bufferedreader reading incoming line from System.in.


Now, I'm not a java programmer, but I'm betting that the redirection of standard input to /dev/null is causing your program to go into a tight polling loop around the bufferedreader (read 0 bytes from System.in, do nothing, select/poll all descriptors including System.in).


Top
   
 Post subject:
PostPosted: Wed Jan 04, 2012 2:54 pm 
Offline
Newbie

Joined: Wed Jan 04, 2012 2:46 pm
Posts: 3
VZ let's you burst to memory that doesn't belong to your VPS and at any time in the future this memory can be reclaimed. Law of Attraction
This is done in a manor similar to the OOM killer in Linux by targeting the biggest processes in memory. personality development
That would always be your Java process.

How to fix this?
Either make sure you never go above by forcefully setting your max heap low enough ( -Xmx256m )
Keep in mind that out of heap space is added on top of your heap, so don't set it for 512mb


Last edited by vpsgeek on Thu Jan 05, 2012 12:15 am, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Wed Jan 04, 2012 4:01 pm 
Offline
Newbie

Joined: Wed Jan 04, 2012 2:46 pm
Posts: 3
I agree with Piki.

You definitely should use "ps aux" it has an interface of list of current running processes, memory used and CPU Consumption. Pretty much all you need to track CPA usage and processes mapping.

I am using the same for a long now.


Top
   
 Post subject:
PostPosted: Wed Jan 04, 2012 11:51 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
vpsgeek wrote:
VZ let's you burst to memory that doesn't belong to your VPS and at any time in the future this memory can be reclaimed. google
This is done in a manor similar to the OOM killer in Linux by targeting the biggest processes in memory.

That would always be your Java process.

How to fix this?


One could also avoid VZ by using a provider such as Linode.


Top
   
 Post subject:
PostPosted: Thu Jan 05, 2012 12:10 am 
Offline
Newbie

Joined: Wed Jan 04, 2012 2:46 pm
Posts: 3
hoopycat wrote:
vpsgeek wrote:
VZ let's you burst to memory that doesn't belong to your VPS and at any time in the future this memory can be reclaimed.

This is done in a manor similar to the OOM killer in Linux by targeting the biggest processes in memory.

That would always be your Java process.

How to fix this?


One could also avoid VZ by using a provider such as Linode.


Sure thing, Linode is always a very good Choice.


Top
   
 Post subject:
PostPosted: Thu Jan 05, 2012 1:06 pm 
Offline

Joined: Thu Jan 05, 2012 1:02 pm
Posts: 1
vpsgeek wrote:
VZ let's you burst to memory that doesn't belong to your VPS and at any time in the future this memory can be reclaimed.

This is done in a manor similar to the OOM killer in Linux by targeting the biggest processes in memory. personality development
That would always be your Java process. Inspirational Quotes



As for burst ram in VZ, I don't know.
I've been at providers like Servint where you could burst all the time without getting processes reclaimed.
I think it's reclaimed when other VPS instances need the memory and there is no more physical memory.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group