Displaying the load the server is under?

On my program I want to display the load the server is currently
under. The application I’m writing can get pretty intense and it
based on a number of factors. I want the user to be able to tell when
they are using the program beyond the server’s limits. Is this
possible? Maybe show the percent of the CPU being used, how much ram
is being used, etc.

Any ideas how the user can go “whoa, maybe I should stop because I’m
maxing out the server”.

Thanks for your help.

Thank You,
Ben J.
E: [email protected]

On 15-Jul-06, at 4:31 PM, Ben J. wrote:

On my program I want to display the load the server is currently
under. The application I’m writing can get pretty intense and it
based on a number of factors. I want the user to be able to tell
when they are using the program beyond the server’s limits. Is this
possible? Maybe show the percent of the CPU being used, how much
ram is being used, etc.

Not really… If you limit CPU usage to a certain percentage,
percentage of CPU usage isn’t going to be helpful. If you don’t,
other factors could (and will) almost always taint that result. The
same caveat applies to testing memory usage.

Also, the load displayed by the unix ‘w’ program (uptime is usually a
hard link to this) will display differently based on different
factors on different unix operating systems. FreeBSD for example uses
the total number of waiting processes to gauge system load, which may
not be the most accurate. Calculating load is a difficult beast. If
perhaps you could tell us what exactly your program does, we may be
able to offer you better solutions.

Ben J.


Jeremy T.
[email protected]

“One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills.” – Mike Vanier

The sad thing is that I can’t really say what my program is for,
because it is confidential. On the other hand, the reason I want to
do this is because I have a background process running that handles
the core work of the program. What this background process does is
create threads that contain while loops that could run forever
depending on the parameters. What I want to make sure they don’t do
is create too many threads in this process that they are exceeding
what the CPU can handle, because if this happens the programs
performance will suffer and performance is the backbone of this
software. Also if it gets to that point I’d like to inform them that
their hardware is constraining the performance of the program.

I wish there was a way to tell them “This program is not optimal
because the hardware is constraining the performance of this
application.” Is there any possible way to do this?

Running the “top” command tells me all kinds of information about the
computer, could something similar to this be used in a ruby application?

Thank You,
Ben J.
E: [email protected]

On 7/15/06, Ben J. [email protected] wrote:

[SNIP]

Running the “top” command tells me all kinds of information about the
computer, could something similar to this be used in a ruby application?

Well if top information is all you want ruby can certainly call top as
a
system call
I wrote a little class that might be useful, be careful about
synchronization though, I have 0 experience with that in ruby! I
immagine
one might implement consumer and producer threads with classical CondVar
design
anyway it seems to work well :wink:

Cheers
Robert
----------------------------- 8< -------------------------------------
#!/usr/bin/ruby -w

require ‘thread’

class TopData

def initialize sleepy=60
    @sleepy = sleepy
    @new = false
    @m = Mutex.new
    @top = Thread.new {
        loop {
            @m.synchronize {
                @data = IO.popen( '/usr/bin/top -bn 1' ).readlines
                @new = true
            }
            sleep @sleepy
        }
    }
end

def new_data?; @new; end

def get_data
    @m.synchronize {
        @new = false
        @data
    }
end

end

t = TopData.new 2
100.times do
puts t.get_data
sleep 2
end

Ben J. wrote:

Thanks for your help.

Thank You,
Ben J.
E: [email protected]

See sys-proctable and/or sys-cpu, available on the RAA.

Regards,

Dan