From 033aecb389bf410d0ff9d16c9265cd07a907d761 Mon Sep 17 00:00:00 2001 From: Patrick Hunt Date: Tue, 27 Oct 2009 00:10:10 -0700 Subject: [PATCH] added option for testing a cluster rather than list of individual servers --- README.textile | 4 ++++ zk-latencies.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index 2ececc5..cf3a66c 100644 --- a/README.textile +++ b/README.textile @@ -88,6 +88,8 @@ Options: -h, --help show this help message and exit --servers=SERVERS comma separated list of host:port (default localhost:2181) + --cluster=CLUSTER comma separated list of host:port, test as a cluster, + alternative to --servers --timeout=TIMEOUT session timeout in milliseconds (default 5000) --root_znode=ROOT_ZNODE root for the test, will be created as part of test @@ -108,6 +110,8 @@ Options: -q, --quiet quiet output, basically just success/failure +The --servers options will test each server in turn while the --cluster option tests a server in the cluster chosen at random. + PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --servers "host:port(,host:port)*" diff --git a/zk-latencies.py b/zk-latencies.py index 178e817..50e875b 100755 --- a/zk-latencies.py +++ b/zk-latencies.py @@ -25,7 +25,9 @@ usage = "usage: %prog [options]" parser = OptionParser(usage=usage) parser.add_option("", "--servers", dest="servers", - default="localhost:2181", help="comma separated list of host:port (default localhost:2181)") + default="localhost:2181", help="comma separated list of host:port (default localhost:2181), test each in turn") +parser.add_option("", "--cluster", dest="cluster", + default=None, help="comma separated list of host:port, test as a cluster, alternative to --servers") parser.add_option("", "--timeout", dest="timeout", type="int", default=5000, help="session timeout in milliseconds (default 5000)") parser.add_option("", "--root_znode", dest="root_znode", @@ -261,14 +263,17 @@ def func(): if __name__ == '__main__': data = options.znode_size * "x" - servers = options.servers.split(",") + if options.cluster: + servers = [options.cluster] + else: + servers = options.servers.split(",") # create all the sessions first to ensure that all servers are # at least available & quorum has been formed. otw this will # fail right away (before we start creating nodes) sessions = [] # create one session to each of the servers in the ensemble - for i, server in enumerate(servers): + for server in servers: sessions.append(ZKClient(server, options.timeout)) # ensure root_znode doesn't exist