Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 26, 2009, 07:00 AM   #1
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Accurately measuring the current load on a Mac

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.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Jun 26, 2009, 09:45 AM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);
That gives the three load values like you see in:

Code:
TwinTurboG5:~ nerfle$ uptime
 9:44  up 23:22, 2 users, load averages: 1.45 1.31 1.12
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Jun 26, 2009, 10:21 AM   #3
Cromulent
Thread Starter
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by Sayer View Post
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);
That gives the three load values like you see in:

Code:
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.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Jun 26, 2009, 10:28 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Use DTrace to read the kernel load variable? As discussed here...
robbieduncan is offline   0 Reply With Quote
Old Jun 26, 2009, 12:01 PM   #5
Cromulent
Thread Starter
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by robbieduncan View Post
Use DTrace to read the kernel load variable? As discussed here...
Heh, I didn't think DTrace handled things like that. I really need to start trying to understand it better. Thanks for the link.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Guess how accurately cable news networks cover climate change? Thomas Veil Politics, Religion, Social Issues 37 Apr 11, 2014 01:03 AM
Measuring LTE signal strength docal97 iPhone 3 Dec 30, 2012 01:11 PM
Just me or is clicker more difficult to engage accurately in iOS6? robaroo iOS 6 6 Oct 8, 2012 02:54 PM
Neither Dock nor Cmd-tab accurately show App open/closed k12s OS X 10.8 Mountain Lion 0 Sep 3, 2012 02:40 AM
Measuring anything? There's an App for that Mppl iPhone and iPod touch Apps 0 Jun 17, 2012 09:00 AM

Forum Jump

All times are GMT -5. The time now is 11:03 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC