zeo-check-max-connections.py — text/python-source, 1 KB (1994 bytes)
Dateiinhalt
#!/usr/bin/python """Connect to a ZEO server and check for maximal connections. Usage: zeo-check-max-conections.py [options] Options: -p port -- port to connect to -h host -- host to connect to (default is current host) -U path -- Unix-domain socket to connect to -S name -- comma separated list of storage names (default is '1') -c connections -- simultaneous connections You must specify either -p and -h or -U. """ import getopt import socket import sys import time from ZEO.ClientStorage import ClientStorage def multiConnect(addr, storages, connections): cs={} for s in storages: for i in range(0,connections): key = '%s-%s' % (s,i) print 'connecting storage %s' % key cs[key] = ClientStorage(addr, storage=s, wait=1, read_only=0) print '%s. connection established' % (len(cs)) # release connections after 10 seconds time.sleep(10) for s in cs.keys(): cs[s].close() def usage(exit=1): print __doc__ print " ".join(sys.argv) sys.exit(exit) def main(): host = None port = None unix = None storages = ['1'] connections = 1 try: opts, args = getopt.getopt(sys.argv[1:], 'p:h:U:S:c:') for o, a in opts: if o == '-p': port = int(a) elif o == '-h': host = a elif o == '-U': unix = a elif o == '-S': storages = a.split(',') elif o == '-c': connections = int(a) except Exception, err: print err usage() if unix is not None: addr = unix else: if host is None: host = socket.gethostname() if port is None: usage() addr = host, port multiConnect(addr, storages, connections) if __name__ == "__main__": try: main() except Exception, err: print err sys.exit(1)