perl CPU utilization and socket I/O

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

  1. skyn3t

    skyn3t 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?
     
    skyn3t, Feb 21, 2007
    #1
    1. Advertisements

  2. skyn3t

    xhoster Guest

    How do you know this? This conflicts with what you report later.
    What did SmallProf/DProf tell you? We can't help you intepret these
    results if you don't tell us what they were.
    I wouldn't expect it to make much of a difference.
    I wouldn't expect that to make a difference, either, unless you are
    using truly nonblocking IO, which is unusual.
    You should be more worried that the your previously reported CPU
    utilization is discrepant with the ratio of (user+sys)/real.
    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.
    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
     
    xhoster, Feb 22, 2007
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.