Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl CPU utilization and socket I/O

Reply
Thread Tools

perl CPU utilization and socket I/O

 
 
skyn3t@gmail.com
Guest
Posts: n/a
 
      02-21-2007
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?

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      02-22-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find cpu utilization for each process on WIndows Platformusing perl zigzagdna@yahoo.com Perl Misc 1 12-04-2008 01:36 AM
KB # 840861 and 100% CPU utilization =?Utf-8?B?UGV0ZXI=?= ASP .Net 0 03-09-2006 02:51 PM
Win2k SP4 - IE and windows explorer go to > 95% CPU utilization when i try to open them! SGT Robo Computer Support 3 07-28-2004 01:51 AM
Help Needed Java NIO server and Tomcat 100% CPU utilization !!!! Avizz Java 1 12-10-2003 06:38 AM
2600XM, Frame Relay, and High CPU Utilization Donald Zelenak Jr. Cisco 5 12-06-2003 01:18 AM



Advertisments