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

I am running my perl(v 5.10.0) script on Mac OS x(10.6.0) with eight cores. In the perl script I've created 8 threads. But when I look at the system's running processes and cpu usage it shows that the perl is using only one core(rather than using all 8 cores). When I run the same script on another Linux server, it works fine (uses all the cores I want). Any thoughts please?

Replies are listed 'Best First'.
Re: Threads Mac Os x
by BrowserUk (Patriarch) on Feb 26, 2011 at 10:00 UTC
    it shows that the perl is using only one core

    This really is most unlikely. It seems far more likely that the tools you are using to monitor the usage, or your interpretation of that information is at fault.

    Though it also seems unlikely that the implementation of a system tool like top on a modern OS could be quite so broken as suggested elsewhere.

    Something as simple as:

    perl -Mthreads -E"async{ my $x; ++$x for 1 .. 100e6 }->detach for 1 .. +8; sleep 10"

    Should red-line all your cpus for a few seconds. If it doesn't, you're either misinterpreting the tools or your perl installation is very broken, but I'd expect some errors if it was the latter.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Have you tried installing "htop" for OSX, and watching the cores independently in a second terminal while it runs?

      htop on osx

Re: Threads Mac Os x
by richardwfrancis (Beadle) on Feb 26, 2011 at 09:43 UTC

    What percent of cpu usage do you see on the Mac using "top"?

    If you have an 8 core machine in one cpu it may manifest itself as a single cpu in "top" but running at 800% (if all threads are taking up 100% of each core)

      I see CPU usage around 100% only. If all the CPUs were being used then I would've seen something like 700% or or higher. When I "top" I see the following: PID COMMAND %CPU TIME #TH 7867 perl5.10.0 96.6 26:15:19 8/6 (where #TH: total number of threas/number of running threads)
        When I "top" I see the following:
        PID COMMAND %CPU TIME #TH 7867 perl5.10.0 96.6 26:15:19 8/6
        (where #TH: total number of threas/number of running threads)

        I would interpret that to mean that at the moment in time when you ran the command, 6 of your 8 threads were running concurrently, and between them they were using 96% of your total cpu capacity.

        In other words, if you have a single threaded process running flat out on a single core, I would expect the highest %cpu value shown to be 100/8 = 12.5%.

        The fact that at the instance that the command ran, only 6 of 8 threads was actually using a core, just means that in that brief instance, some other higher priority processes--like your display driver, or your network driver, or your disk driver--needed to do something.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Threads Mac Os x
by Your Mother (Archbishop) on Mar 01, 2011 at 00:13 UTC

    Given the advice from agent_smith

    sudo port install htop Password: ---> Computing dependencies for htop ---> Fetching htop ---> Verifying checksum(s) for htop ---> Extracting htop ---> Configuring htop ---> Building htop ---> Staging htop into destroot ---> Installing htop @0.8.3_1 ---> Activating htop @0.8.3_1 ---> Cleaning htop

    And running the sample from BrowserUk, I see this, on my ageing MacBook, with htop

    1 [||||||||||||||||||||||||||||||||||||||100.0%] Tasks: 139 tot +al, 3 running 2 [||||||||||||||||||||||||||||||||||||||100.0%] Load average: +2.68 1.35 0.96 Mem[|||||||||||||||||||||||||||||||||3802/4096MB] Uptime: 19 day +s, 20:59:05

    Nice!