Skip to content

Commit

Permalink
added option for testing a cluster rather than list of individual ser…
Browse files Browse the repository at this point in the history
…vers
  • Loading branch information
phunt committed Oct 27, 2009
1 parent dba4e6a commit 033aecb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.textile
Expand Up @@ -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
Expand All @@ -108,6 +110,8 @@ Options:
-q, --quiet quiet output, basically just success/failure
</pre>

The --servers options will test each server in turn while the --cluster option tests a server in the cluster chosen at random.

<code>
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --servers "host:port(,host:port)*"
</code>
Expand Down
11 changes: 8 additions & 3 deletions zk-latencies.py
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 033aecb

Please sign in to comment.