PDA

View Full Version : Accurately measuring the current load on a Mac




Cromulent
Jun 26, 2009, 07:00 AM
I'm trying to add a little feature that takes the current load on a computer and then sends it back to a central server (same computer or different computer it does not really matter) and then the server routes network requests based on the load of the registered servers with it.

What is the best way of getting current load on a Mac for a system such as this? It is a C only application I am afraid so no Cocoa / Objective-C.



Sayer
Jun 26, 2009, 09:45 AM
Use the stdlib function "getloadavg()" like this:

double loads[3];

getloadavg(loads, 3);

That gives the three load values like you see in:

TwinTurboG5:~ nerfle$ uptime
9:44 up 23:22, 2 users, load averages: 1.45 1.31 1.12

Cromulent
Jun 26, 2009, 10:21 AM
Use the stdlib function "getloadavg()" like this:

double loads[3];

getloadavg(loads, 3);

That gives the three load values like you see in:

TwinTurboG5:~ nerfle$ uptime
9:44 up 23:22, 2 users, load averages: 1.45 1.31 1.12

The problem with that is it is not accurate enough. The servers performance will be quite variable and as such I think the load average might not offer the kind of information I need.

I mean obviously it does give you an idea, but it is still reasonably general.

Edit : I guess it might actually do the job if I just call it more than once a minute and take the moving average of the average load over a one minute period.

robbieduncan
Jun 26, 2009, 10:28 AM
Use DTrace to read the kernel load variable? As discussed here (http://mail.opensolaris.org/pipermail/dtrace-discuss/2008-March/005901.html)...

Cromulent
Jun 26, 2009, 12:01 PM
Use DTrace to read the kernel load variable? As discussed here (http://mail.opensolaris.org/pipermail/dtrace-discuss/2008-March/005901.html)...

Heh, I didn't think DTrace handled things like that. I really need to start trying to understand it better. Thanks for the link.