Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

My CGI is slow, but I don't think it's my fault.

by jimt (Chaplain)
on Mar 03, 2007 at 01:33 UTC ( [id://603004]=perlquestion: print w/replies, xml ) Need Help??

jimt has asked for the wisdom of the Perl Monks concerning the following question:

For some reason, my website has gotten progressively slower over the last few months. I don't think I've changed anything to yield these results.

Here's what I know - the scripts run lightning fast hosted on my local machine. Now, while I love my powerbook dearly, it is, admittedly, not exactly state of the art. Yes, yes, I know that I'm the only one hitting the webserver and I don't need to worry about network latency. I was sure to bring down a fresh database from the live site to be sure to compare identical data. Still. I ran it through Devel::DProf, and got this:

Total Elapsed Time = 2.282964 Seconds User+System Time = 1.392964 Seconds

Not too shabby. I can live with that. So then I ran the same thing through Devel::DProf on the hosted site:

Total Elapsed Time = 18.89348 Seconds User+System Time = 0.793482 Seconds

Eek. Behold the disastrous slowdown. And now I'm stumped. If my User+System Time were high, then no sweat - slog through the code, find slow things, optimize 'em away. Fun stuff. But this? This is external, and out of my control. Right?

So basically, I'm ruling out network problems, database issues, and generally anything in my script and seem to be at a point of blaming my host. FWIW, it's 1&1. So their hardware should be absolutely massive. But what could this be indicative of? Some sort of throttling? Restrictions? Essentially, before I begrudgingly begin the long, annoying path of switching hosts, I want to know if there's something - anything else I could/should be looking at to spare me the pain.

Replies are listed 'Best First'.
Re: My CGI is slow, but I don't think it's my fault.
by perrin (Chancellor) on Mar 03, 2007 at 14:38 UTC
    It probably just means the database on your host is very slow. How about showing us the rest of that DProf output, sorted by wall time? Then it would be obvious where the time was going.

      And Perrin gets the gold star. Right on both counts.

      Re-profiling with dprofpp -r (d'oh. There's an option which I'll need to remember) yielded:

      Total Elapsed Time = 22.28669 Seconds Real Time = 22.28669 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name 59.2 13.20 13.200 314 0.0420 0.0420 DBI::db::ping

      Basically, every time it tried to grab a cached database handle, it would ping it first to make sure it was still valid. Useful in persistent environments (mod_perl, etc.) or long running scripts, but not so much on a website that's all CGI and nothing survives long. I figured I could take the risk of having the database handle vanish in that time, so I shut off the constant re-pinging.

      Next profile dropped the total run time down to 5.45 seconds, with 83% of my time spent executing queries. Much more reasonable. And I'm sure I can get that runtime down even farther with some judicious indexing.

      Thanks!

Re: My CGI is slow, but I don't think it's my fault.
by hangon (Deacon) on Mar 03, 2007 at 02:42 UTC

    Hosting companies try to put as many sites as they can on each box. You may be seeing the effect of increasing traffic to the server where your site is hosted, due to adding more sites and/or existing sites drawing more traffic. One thing you can try is asking them to move your account to a different server.

Re: My CGI is slow, but I don't think it's my fault.
by rhesa (Vicar) on Mar 03, 2007 at 01:52 UTC
    It doesn't necessarily need to be the host (a sleep 18 in your code would give similar timing), but it does sound like a system issue.

    Have you checked how busy that machine is? Check some of these commands:

    uptime free ulimit df -H ps aux
    You get the idea.

    If those aren't the issue, is connecting to the database a problem? Opening sockets? What else does your code do that interacts with the OS?

Re: My CGI is slow, but I don't think it's my fault.
by thezip (Vicar) on Mar 03, 2007 at 02:33 UTC
    You may want to write and install a *very* simple program that recreates/demonstrates the problem, but removes all of the complexity of the main CGI application...

    Where do you want *them* to go today?
Re: My CGI is slow, but I don't think it's my fault.
by kyle (Abbot) on Mar 03, 2007 at 01:46 UTC

    Some sort of throttling? Restrictions?

    Have you asked them?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://603004]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found