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

How to hobble a CPU

by Solostian (Beadle)
on Jun 07, 2006 at 15:18 UTC ( [id://554047]=perlquestion: print w/replies, xml ) Need Help??

Solostian has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I need to conduct a series of performance tests.
Unfortunately, my workstation is way more powerful than the targeted workstations.
I need to design a script that will allow me to cut down the overall CPU power by a set % value.

Does anyone knows if this is possible at all with Perl?
Where would I first need to look?

Regards,
Solostian

-- "Fortunately, ridicule does not kill..."

Replies are listed 'Best First'.
Re: How to hobble a CPU
by socketdave (Curate) on Jun 07, 2006 at 15:30 UTC
    What OS are you running? BSD::Resource can tweak the priority and resource limits of your script on most unix-like systems, although I don't think that this is what you're looking for. There is a freeware program called "CPU speed adjuster" for Windows: http://www.adrianboeing.com/tools.html

    It may be closer to what you need even though it's not a Perlish solution.
      That tool looks great! Thanks a lot!

      Regards,
      Solostian

      -- "Fortunately, ridicule does not kill..."
Re: How to hobble a CPU
by Fletch (Bishop) on Jun 07, 2006 at 15:26 UTC

    Install Windows. *Bah dum dum*

    Seriously though, if you'll give a bit more information like (ironically enough) the OS you're trying to test on you may get better answers.

      I need to conduct the tests on Win32.

      Regards,
      Solostian

      -- "Fortunately, ridicule does not kill..."
Re: How to hobble a CPU
by davido (Cardinal) on Jun 07, 2006 at 15:37 UTC

    How much would a system equivalent to your target workstations cost? Maybe it's a justifiable expense to get hold of a workstation that is more closely similar to your targets. ...perhaps eBay? ;)

    I would be concerned that anything you use to load up the CPU of your current development system won't closely enough replicate the feel of working on a less advanced system. It's pretty difficult to consume exactly enough CPU cycles through brute force to mimic the feel of an older-generation CPU.


    Dave

Re: How to hobble a CPU
by VSarkiss (Monsignor) on Jun 07, 2006 at 15:35 UTC

    If you're trying to do an overall performance test, CPU speed (or "power") is only one factor. If your task is I/O bound it may even be a negligible factor.

    In general, trying to scale performance numbers is difficult. You may want to try running some baseline tests a few times on each platform to see if the results are comparable. If so, you could then proceed with testing on your machine and scaling the results up or down. It's not perfect, but it's probably reasonable.

    You can use Perl tools like Benchmark.pm for conducting the tests, but the problem itself is much broader.

      The test is a mix of both raw CPU power and I/O.
      The workstation is receiving a lot of records (5000+) thru the LAN and needs to add them to a cockpit. The cockpit is refreshed after each received record.
      The deployed workstations are about 50% less powerful (CPU, RAM) than my workstation and they can't refresh the cockpit quickly enough while mine can.

      Regards,
      Solostian

      -- "Fortunately, ridicule does not kill..."

        /me cringes at this idea.

        I'm assuming you have a reason for refreshing constantly...but is it a realy realy good reason? I mean wouldn't refreshing after batches work better for both stations with probably limited impact on the actual use? It is hard to tell, but realy if you want the performance of your target machine then test it on your target machine, thats the only way you are going to know how well it will run on the target machine.

        Best of luck


        ___________
        Eric Hodges
Re: How to hobble a CPU
by sgifford (Prior) on Jun 07, 2006 at 15:38 UTC
    If your CPU supports frequency scaling as a power saving feature, you may be able to use that to slow it down.

    Another option is running another process which hogs the CPU; if you alternate between performing some CPU-intensive operation and yielding control to other processes, you should be able to fiddle with how much time is spent doing each to get the other process to consume the amount of CPU you would like, and if you make sure the hogging process has a higher priority than the process being tested, that should approximate a slower CPU.

    A third option is running it on the high-speed machine and dividing all the results by 4 to simulate a machine 1/4 the speed. :)

Re: How to hobble a CPU
by gellyfish (Monsignor) on Jun 07, 2006 at 15:32 UTC

    On certain OS you could install a "vertical refresh interrupt handler" that would get called with the frequency of your display's refresh rate, if you caused this to take the appropriate amount of time you could significantly reduce the amount of time allocated to run user programs. Of course you can't do this with Perl.

    /J\

Re: How to hobble a CPU
by girarde (Hermit) on Jun 08, 2006 at 16:17 UTC
    I suspect that a script to spawn an arbitrary number of processes calculating Fibonacci numbers up to ~2^32 and starting over again indefinitely would do the trick.

    The number of processes might need to be pretty big, but that's configurable.

Re: How to hobble a CPU
by Withigo (Friar) on Jun 08, 2006 at 07:45 UTC
    Perhaps running "renice" on the pid of the process that you want to run at a slower speed might have a close enough effect ? This assumes you're running *nix; I don't believe renice has been ported to Windows.
      I don't believe renice has been ported to Windows.

      You can adjust process priorities directly through the task manager. Unfortunately, doing so wouldn't work for either OS. No matter how low you set the priority, if there is nothing else utilitising the cpu, the even an idle priority task will receive close to 100% cpu if it wants it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-23 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found