Jump to content

CPU usage


Jayvnl

Recommended Posts

Hi,

 

My hosting disabled my account because my site used too many system resources (CPU).

There is no way for me to know how much CPU my site is using since i am not a psychic or god so no clue how they expect me to monitor this or fix this (the site has been running just fine for 2 years with the same code).

 

Is there any code that can tell me how much CPU my site is using on the server?

 

Thanks in advance,

 

Jay

Link to comment
Share on other sites

http://phpsysinfo.sourceforge.net/

 

you can't actually check how much CPU your script is running although you can add a timestamp to start at top of page

and a subtract it from a new timestamp reading to get a value how long it took your site to load but it doesn't reflect the cpu usage i guess.. and you can tell that you site loads under a second etc..

 

blah completely off topic tbh nothing can really do this unless you have remote access of the machines desktop/terminal

Link to comment
Share on other sites

Thank you for the reply :)

 

I know they are being completely unprofessional about this and i don't know what i can do to make it better so that they will lift the block on my account...

Is there a way to 'slip' php code or something to make it run smoother/faster/better ? (i know that's off topic).

 

Anyway thanks :)

Link to comment
Share on other sites

It's somewhat your web host's responsibility to provide you with as much information that they know about the problem, not just to say your site consumed too many resources.

 

You would need to know which pages where being requested and how frequently they were being requested at the time the over-usages occurred (perhaps your site just got popular enough that you need to move it to a plan that provides more resources.) Someone could also have hijacked part of your site and is using it to host their media files or as a phishing site. Have you checked if your files are the only ones present?

 

For any particular page (hopefully the one(s) that are causing the problem), you can look at ways to reduce the amount of processing. We would only be able to help if you posted actual code for a page. You might need to make use of some caching to prevent processing the same information over and over for each page request.

Link to comment
Share on other sites

JustHost

 

Worst choice of my life.....

Lots of downtime, horrific support and as i found out today..... no warning or heads up but a suspended account without clarifying or trying to suggest fixes.

 

The fix they did offer was to move to a dedicated server (135 bucks a month), wish i had the money for that! lol

Link to comment
Share on other sites

If you have access to the access log, you can look for any large groups of requests, pick the most frequently requested file, and attempt to optimize its cpu usage.

 

You can also look at the access log for anything that is being requested that should not be (perhaps someone is probing your site either to break in or to trigger errors to shut your site down.)

 

There are probably 50 different things that your code could be doing that are wasteful of processing time, such as including a file using a URL instead of a file system path, performing the same query more than once on a page, putting queries inside of loops ...

Link to comment
Share on other sites

Monthly stats show i have between 50 and 60GB bandwidth use and between 6 and 7 million hits.

While i have no clue how the bandwidth could be that high the hits are pretty much the same as they have always been.

I will check logs, dig through my FTP and such to make sure everything is in order.

Link to comment
Share on other sites

It looks like caching is the answer to my issues from what i read after googling it.

Does anyone have a good noobie site/tutorial that will tell me how i can start implementing this?

(i know 000.1% PHP, a buddy did all the coding and he won't be available til December... so i'm on my own :/)

Link to comment
Share on other sites

I put the code in a new php page, uploaded it and when i load it i just see a blank page.

 

This is the code i put in:

 

<?php
$load = sys_getloadavg();
if ($load[0] > 80) {
    header('HTTP/1.1 503 Too busy, try again later');
    die('Server too busy. Please try again later.');
}
?>

 

What does the 80 stand for in this case? Percent cpu load or... ?

What kind of tweaks do i have to make to get this to work, it looks like this script will automatically deny webpage access if the load becomes too high, just what i need!

 

Link to comment
Share on other sites

the function sys_getloadavg() returns an array of the system load average 1 minute ago, 5minutes ago and 15minutes ago.

You're code is not returning anything because it is not greater than 80, it returns the number of processes queued up for execution.

 

You can do

print_r(sys_getloadavg());

and it will return the array with those three values.

 

You're code if if($load[0] > 80) will work, but only if the load avg 1 minute ago was > 80. You'll need to change 80 to a value which corresponds to a high system load on your server, and what that value is I don't know, you'll have to play around with it and find out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.