Page 1 of 1

Big CPU load problem on a Php/MySQL linksite

Posted: Mon Jan 31, 2005 7:21 am
by Ozz
I got a CPU load problem on my Php/MySQL based Link site. Site gets 3000-4000 unique visitor and 70.000-100.000 page hits. Its not too many traffic I think. After my hosting (Shared) complained about CPU load 2 months ago I reduced MySQL queries and remove some sections on site. But its not worked. Then I used a Cache system and included cached files on the site. Queries decreased 80%. But thats not decreased CPU load too. I have learnt "ob_start()" function uses CPU to compress file. I was using it for a long time and I removed it. Guess what,that's not worked too.
I wonder that how can I be sure what's making this CPU load. Which part of site or which code, function? Php or MySQL?
I heard some debug tool, benchmark tests.
Is there a way to know whats going on in the code?
What tool (script) do you recommend?

I tried PhpED Debug Profiler tool and it tells this database connection is takes most of execution times:
$connection = @mysql_connect($dbhost, $dbuser, $dbpass)
or die ("Can not connect to database");
$db = @mysql_select_db($dbname, $connection)
or die ("Can not select database.");

I use this database connection on config.inc file. On my site outgoing links open in a new window and every link has a frame to count hits, commenting and voting. So every click makes a database connection to UPDATE hit value.
I think this can make that CPU load problem.
Is there any difference between using mysql_connect and mysql_pconnect?
Maybe I must use file based counting system which I dont prefer. What do you think?
I dont understand how can 3000 visitors make that problem. Also in Cpanel I see %2 or %3 cpu load but it has a red sign. Shared hostings say they allow "10%-20%" CPU usage. So what's wrong on my condition?

Please help me to get rid off this problem. I tried 3 hosting provider and same problem comes up. Do I need a dedicated host for this site ? (!!!) :?:

Posted: Mon Jan 31, 2005 7:38 am
by feyd
with this level of visitors, you probably need to upgrade to dedicated hosting as shared hosting typically isn't set up for that high of traffic volume.

You could try using persistant connections, this would speed the connection process.

btw. if you see 2.xx that's 200% cpu load, not 2%