473,385 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1027
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.