Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

getting more resource from perl

by jesuashok (Curate)
on Nov 09, 2005 at 15:26 UTC ( #507093=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Suppose If am running a program called "more_cpu.pl".

Is there a way to tell "more_cpu.pl" that get more resource from CPU.

I want to do this from "more_cpu.pl" not through any OS commands.

"Keep pouring your ideas"

Comment on getting more resource from perl
Re: getting more resource from perl
by Fletch (Chancellor) on Nov 09, 2005 at 15:31 UTC

    Erm . . . /boggle

    Congratulations, this is so obscure and poorly woorded I can't even come up with a starting point to make a sarcastic comment to that effect.

Re: getting more resource from perl
by marto (Chancellor) on Nov 09, 2005 at 15:40 UTC
    I believe that jesuashok wants to get the script to use more CPU resource so that it will execute faster.
    This topic has been touched on in the past, a Super Search for something like 'increase cpu' would return the results of the previous questions.

    Hope this helps.

    Martin
      Hi,

      I have already done super searching for this. But I am ablet to find only the answers related to Fork.

      "Keep pouring your ideas"
Re: getting more resource from perl
by duff (Vicar) on Nov 09, 2005 at 15:58 UTC

    You want your program to get access to more resources by issuing some non-OS-command in your program? No, you can't do this.

      In unix terminology, "command" means executable. You're thinking of system calls. Basically, the OP wants a function or module that does the same as nice. It would have been nice if had specified the OS on which this script will run.
Re: getting more resource from perl
by ikegami (Pope) on Nov 09, 2005 at 16:14 UTC

    You may want to search for "priority" and "nice". Those are both related terms. I cam accross these two solutions:

    For some/many unixes, Proc::ProcessTable::Process provides the method priority.

    For Windows,

    use Win32::Process; my $obj; Win32::Process::Open($obj, $$, 0); $obj->SetPriorityClass(HIGH_PRIORITY_CLASS);

    By the way, trying to get *more* CPU is not likely to make your script execute faster on a desktop system (if that's what you have). Desktop systems tend to be idle almost all the time, so there's no CPU time to steal from other applications. Needing more CPU is usually a sign of inefficient code and/or of a need of better hardware. All too often the former.

    Update: Searched and found a unix and Windows module. Updated the node accordingly.

Re: getting more resource from perl
by jeffa (Chancellor) on Nov 09, 2005 at 16:18 UTC

    I have used BSD::Resource in the past to do the opposite of what you want -- to limit the amount of CPU a process can hog. Usually, if i need more CPU resources ... i buy more RAM and/or a faster CPU.

    Questions: What is the real problem? Are you really sure that you need more CPU resources? Are you sure that your problem can't be solved by optimizing your code instead? Can you show us the code you are working with?

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: getting more resource from perl
by QM (Vicar) on Nov 09, 2005 at 22:53 UTC
    You may be asking the wrong question.

    Why do you need more CPU time? Is your process not getting all available time? Is it competing with other processes? (If so, why can't those other processes use less time?)

    Is the process IO bound? If so, getting more CPU time won't help. One way to check this is to simulate all IO by generating fake data for the process to chew on, but don't read or write from disk or other resources outside of the CPU/memory group. If the process suddenly speeds up by an order of magnitude, you need faster IO, not more CPU time. On the other hand, if simulating IO doesn't change the behavior, then either the process is swapping memory to disk, or it's CPU bound.

    If it's CPU bound, do you know why? What part of the process is taking the most time? Have you profiled it with one of the Devel profiling modules? (My favorite is Devel::SmallProf, though there are others with different strengths.])

    You might also look at How (Not) To Ask A Question.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://507093]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-11-27 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (178 votes), past polls