Re: reducing perl cpu usage

2013-01-16 Thread budi pearl
Hi Jim,

On Tue, Jan 15, 2013 at 12:51 AM, Jim Gibson  wrote:

>
> On Jan 13, 2013, at 8:22 PM, budi pearl wrote:
>
>
> Why do you want to reduce your CPU usage?
>
> That may seem like a silly question (who wouldn't want to reduce their CPU
> usage), but the answer to that question will affect the suggestions you
> will get. Is your program taking too long to run? Is it slowing down other
> programs? Are you on a shared system and the other users complaining about
> your program being a CPU hog?
>
>
"Are you on a shared system and the other users complaining about your
program being a CPU hog?"

Yes, this is my problem. I have no problem if my program take longer to
finished as its not too critical and not time sensitive. But yes, it
heavily use I/O so it alway consume proc and cpu.

A side question. I slurp big files and put into hash. Does %hash = () or
%hash = undef will clear up and return free memory to system?

--budi


Re: reducing perl cpu usage

2013-01-14 Thread Jim Gibson

On Jan 13, 2013, at 8:22 PM, budi pearl wrote:

> Hi All,
> 
> Is there any way to reduce the processor usage by perl?
> I am trying to use nice -19 but proc usage is still 100%
> 
> Tasks: 189 total,   2 running, 187 sleeping,   0 stopped,   0 zombie
> Cpu(s):  0.0%us,  0.5%sy, 26.0%ni, 73.5%id,  0.0%wa,  0.0%hi,  0.0%si,
> 0.0%st
> Mem:   4042684k total,  3463524k used,   579160k free,   249812k buffers
> Swap:  4095992k total,0k used,  4095992k free,  2542732k cached
> 
>  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
> 24652 budi   39  19  186m  97m 1980 R 100.0  2.5   3:03.78 route_processor
> 24304 budi   15   0 88112 1768 1036 S  1.8  0.0   0:00.08 sshd
>1 root  15   0 10364  692  580 S  0.0  0.0   0:06.62 init
>2 root  RT  -5 000 S  0.0  0.0   0:19.63 migration/0

Why do you want to reduce your CPU usage?

That may seem like a silly question (who wouldn't want to reduce their CPU 
usage), but the answer to that question will affect the suggestions you will 
get. Is your program taking too long to run? Is it slowing down other programs? 
Are you on a shared system and the other users complaining about your program 
being a CPU hog?

You should not be concerned just because your program is taking 100% of a CPU. 
That is as it should be. If there are no other significant processes running, 
your program will utilize 100% of the available CPU unless it is blocked 
waiting for system resources, such as input or output. Changing the priority of 
your Perl program will not affect that. You want your program running as much 
as possible so that it completes its task in the minimum amount of time.

Only if your Perl program is competing for CPU or other resources will changing 
the priority have any effect. If your program is slowing down other programs, 
then changing the priority is the way to go (but do read 'man nice' and use a 
positive number). If that doesn't work, then you can try limiting the resources 
your program uses. For CPU usage, you can sprinkle sleep(1) statements in your 
program. However, that will result in your program taking longer to complete 
its task and may result in wasted CPU cycles. If your program has more work to 
do, and no other program wants to use the CPU, then you really want the CPU to 
be busy executing your program.

The best way to reduce your program's CPU usage program is to make your program 
more efficient. You can either do the same amount of work more efficiently, or 
do less work by improving your algorithm.

However, we really need to know what problem you are trying to solve to better 
advise you.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reducing perl cpu usage

2013-01-14 Thread Shawn H Corey
On Mon, 14 Jan 2013 11:22:18 +0700
budi pearl  wrote:

> Is there any way to reduce the processor usage by perl?
> I am trying to use nice -19 but proc usage is still 100%

According to the man page, you should try: nice 19

See http://linux.about.com/library/cmd/blcmdl1_nice.htm


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reducing perl cpu usage

2013-01-14 Thread David Precious
On Mon, 14 Jan 2013 11:22:18 +0700
budi pearl  wrote:

> Is there any way to reduce the processor usage by perl?
> I am trying to use nice -19 but proc usage is still 100%

Depends what your code is doing.  If you're doing a continuous loop or
something, yes, you'll eat up CPU.

Devel::NYTProf can be awesome to see where your code is spending most
of its time, so you know where to focus.


-- 
David Precious ("bigpresh") 
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




reducing perl cpu usage

2013-01-13 Thread budi pearl
Hi All,

Is there any way to reduce the processor usage by perl?
I am trying to use nice -19 but proc usage is still 100%

Tasks: 189 total,   2 running, 187 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.5%sy, 26.0%ni, 73.5%id,  0.0%wa,  0.0%hi,  0.0%si,
0.0%st
Mem:   4042684k total,  3463524k used,   579160k free,   249812k buffers
Swap:  4095992k total,0k used,  4095992k free,  2542732k cached

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
24652 budi   39  19  186m  97m 1980 R 100.0  2.5   3:03.78 route_processor
24304 budi   15   0 88112 1768 1036 S  1.8  0.0   0:00.08 sshd
1 root  15   0 10364  692  580 S  0.0  0.0   0:06.62 init
2 root  RT  -5 000 S  0.0  0.0   0:19.63 migration/0

--budi