Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
OK, so your system is capable of running something like 150 perl CGI requests/sec, for a CGI which does very little (the printenv.cgi).

So the difference is in what your code does, so you need to work out what it is doing which is slow and then think about whether that is reasonable amount of time for that work and if you can speed it up if not. (If your code downloads 1Mbyte from a remote site and you are bandwidth limited then tweaking your code won't really help).

Measuring which bits of your code take time is called profiling. There are some good perl modules to help with this, e.g. Devel::Profile and Devel::DProf. These are easier to use on a command line application than a CGI, so one thing you might want to do is to first get to a stage where you can run your CGI as a command line app.

If your CGI doesn't rely on any parameters to demonstrate the slowness, you can try simply: perl my.cgi < /dev/null > output.html. If this reproduces the slowness, then you can try using the profiling tools to work out where it is spending it's time.

Profiling is a bit of an art, and it is very easy to read the results wrongly, so I'd always recommend using more than one approach or tool, to cross-check your data. In particular, simply using Time::HiRes and adding some logging with hires timing to your app can help show where time is being spent.

If your application isn't CPU bound (and it's quite likely not to be), then profiling may be of less help. In this case, you need to work out what your code is doing. The strace utility can be good for this, but again, can require some expertise to interpret. You can turn on timestamps from the strace output which can help you work out where the time is going.

And as a last thought (and perhaps the thing to try first), if your code is connecting to other servers you could be getting hurt by connection times, DNS lookup times etc. You could try time ping some.host to get an idea of the time taken for a process on your box to resolve 'some.host' and get a network packet to and from the remote host. If ping doesn't work for you, you can always use time wget some://url.on.that.host if you are fetching a remote HTTP page, say.


In reply to Re: Why can code be so slow? by jbert
in thread Why can code be so slow? by freakingwildchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-25 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found