472,354 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

testing machine responsiveness

I have a bunch of processes that I farm out over several HPux machines on
the network. There are 60 machines to choose from and I want to
(1) find out which ones are alive (the 'ping' method below) and
(2) sort them by their current load (the 'get' method below, using the rup
command)

I'm no expert--I bet what I'm doing could be done better. I'd appreciate any
tips, caveats, etc.
Thanks in advance for looking at the code.
--Tim Arnold
Say the host names are in a global list tmpList...
#---- The final sorted list of cpus is called as:
cpuList = [x[1] for x in Machines().get()]

#----
class Machines(object):
' List of available, alive machines. '
def __init__(self):
global tmpList
self.asList = [y for y in tmpList if self.ping(y)]
self.asString = ' '.join(self.asList)

def ping(self, cpu):
''' Determine whether a machine is alive.
tcp connect to machine, port 7 (echo port).
Response within 3 seconds -return true
'''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
try:
s.connect((cpu,7))
except:
return 0
try:
s.send('test')
s.recv(128)
s.close()
return 1
except:
return 0

def get(self, maxLoad=3.0,):
''' return sorted list of available machines, sorted on load.
Optionally, specify maxload, default is no more than 3.0
'''
tmpDict = {}
retList = []
try:
rup = os.popen('rup %s | sort -n -t, -k4 | grep day' %
(self.asString))
except OSError:
return self.asList

for s in rup:
(name, t0) = s.split(' ',1)
(t1,t2,t3,avgLoad,t4) = s.split(',')
load = float(avgLoad)
if load < maxLoad:
tmpDict['%s.com' % name] = load

for (l, n) in [(v[1], v[0]) for v in tmpDict.items()]:
retList.append((l, n))
retList.sort()
return retList
Oct 6 '06 #1
1 996
In message <eg**********@foggy.unx.sas.com>, Tim Arnold wrote:
try:
s.connect((cpu,7))
except:
return 0
try:
s.send('test')
s.recv(128)
s.close()
return 1
except:
return 0
Call me nervous, but I like to make my "except" clauses as specific as
possible, to catch only the errors I'm expecting. This is to minimize the
chance of some hidden bug sneaking through and causing the wrong behaviour.
>
try:
rup = os.popen('rup %s | sort -n -t, -k4 | grep day' %
(self.asString))
except OSError:
return self.asList
So if the rup call fails, you're returning a plain list of all the
hostnames? Won't this cause the following parsing to fail?

If you're going to trigger a failure, isn't it better for it to happen as
close as possible to the actual cause? In other words, take out the
try/except block above and let the os.popen call itself directly signal an
exception on failure.

Disclaimer: I've never actually used rup. :)
Oct 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Melvin | last post by:
Hello all, I just want to throw this out here as an idea I have and wanted some input and/or direction. I am currently working as a software developer and we have run into an issue with our...
56
by: Don G | last post by:
I currently have IE6 and Firefox installed on my machine, and I switch between the two when testing web sites I am working on. It is my understanding that IE5 is still pretty common. Is this...
2
by: Robert Hooker | last post by:
I have a fiarly high powered machine for development. This is a bit of curse at times though, since I am sometimes not exposed to the bottlenecks for performance that a lower spec machine might be...
2
by: Stephen | last post by:
Hi, I have developed my application using VS.NET and used project properties to both IE and Netscape. I am testing my application on IE and Netscape. The pages appear perfect on IE but totally...
0
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and...
25
by: Nathan Sokalski | last post by:
As we all know, IE7 is now available. However, it also cannot be installed side by side with IE6. This makes it very hard to test pages on both versions using the same machine. I am guessing that...
19
by: adminloozer | last post by:
Hello, Is there a solution to test on local HD a site under differents IE version. I use Vista and I have IE7. Can I install (with a kind of procedure) older versions of IE. I tried with...
0
by: techiebrandon | last post by:
I have been put in charge of running stress tests to monitor DB2's memory usage. I have never had to do stress testing myself and am fairly new to the area, so I am in foreign territory. I have found...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.