perl CPU utilization and socket I/O

Discussion in 'Perl Misc' started by skyn3t@gmail.com, Feb 21, 2007.

  1. Guest

    I have a perl cgi script that reads from the network and outputs about
    40K per second to the caller.

    The script is averaging about 15-25% CPU utilization, when it isn't
    doing much other than reading from the network, parsing the message,
    and printing it. I want to get this CPU utilization down.

    Things I have tried:

    (1) Use SmallProf/DProf to get profiling information on the script and
    make adjustments. I made quite a few perl optimizations based on this
    data and it barely dented the CPU utilization.
    (2) Convert the script to use sysread() to read the data in larger
    chunks than the perlio libs do. This did not change the CPU
    utilization at all.
    (3) Select on the socket before attempting reading from it, and bail
    if there is no data. Didn't help CPU.

    So what's causing it? I'm stumped.

    Here is what a 2 minute "time" call to my script looks like:

    real 2m8.469s
    user 0m1.557s
    sys 0m0.795s

    Should I be worried about the large discrepancy between the real time
    and the user+sys time? This indicates that perl is idling quite a bit,
    correct? Is this normal for a perl application?

    Any thoughts on how I can determine where the CPU utilization is
    coming from?
     
    , Feb 21, 2007
    #1
    1. Advertising

  2. Guest

    wrote:
    > I have a perl cgi script that reads from the network and outputs about
    > 40K per second to the caller.
    >
    > The script is averaging about 15-25% CPU utilization, when it isn't
    > doing much other than reading from the network, parsing the message,
    > and printing it.


    How do you know this? This conflicts with what you report later.

    > I want to get this CPU utilization down.


    Why?

    >
    > Things I have tried:
    >
    > (1) Use SmallProf/DProf to get profiling information on the script and
    > make adjustments. I made quite a few perl optimizations based on this
    > data and it barely dented the CPU utilization.


    What did SmallProf/DProf tell you? We can't help you intepret these
    results if you don't tell us what they were.

    > (2) Convert the script to use sysread() to read the data in larger
    > chunks than the perlio libs do. This did not change the CPU
    > utilization at all.


    I wouldn't expect it to make much of a difference.

    > (3) Select on the socket before attempting reading from it, and bail
    > if there is no data. Didn't help CPU.


    I wouldn't expect that to make a difference, either, unless you are
    using truly nonblocking IO, which is unusual.

    >
    > So what's causing it? I'm stumped.
    >
    > Here is what a 2 minute "time" call to my script looks like:
    >
    > real 2m8.469s
    > user 0m1.557s
    > sys 0m0.795s
    >
    > Should I be worried about the large discrepancy between the real time
    > and the user+sys time?


    You should be more worried that the your previously reported CPU
    utilization is discrepant with the ratio of (user+sys)/real.

    > This indicates that perl is idling quite a bit,
    > correct? Is this normal for a perl application?


    There is no normal for a Perl application. A Perl program that is IO
    bound will look pretty much like a non-Perl program that is IO bound.
    A Perl program that is CPU bound will look pretty much like a non-Perl
    program that is CPU bound.

    > Any thoughts on how I can determine where the CPU utilization is
    > coming from?


    That is more of a systems problem than a Perl problem. If I couldn't
    figure out was going on using the system tools, then I'd make some
    systematic changes to the program and see what happens. What if it reads
    from the socket and parses it, but just throws it away rather than
    printing? What if it reads from the socket, and throws it away without
    either parsing or printing? What if it reads and then prints gibberish,
    rather than parsing what it read?

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Feb 22, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGV0ZXI=?=

    KB # 840861 and 100% CPU utilization

    =?Utf-8?B?UGV0ZXI=?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    447
    =?Utf-8?B?UGV0ZXI=?=
    Mar 9, 2006
  2. Avizz
    Replies:
    1
    Views:
    4,444
  3. Imran
    Replies:
    1
    Views:
    412
    bruce barker
    Oct 6, 2008
  4. Holmbrew
    Replies:
    3
    Views:
    5,974
    Holmbrew
    Feb 5, 2009
  5. Replies:
    1
    Views:
    145
    Thrill5
    Dec 4, 2008
Loading...

Share This Page