perl CPU utilization and socket I/O

S

skyn3t

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?
 
X

xhoster

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top