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 %MEM TIME+ 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 0 0 0 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/