Skip to content

Commit

Permalink
Merge branch 'readconfig' of git://github.com/sambrightman/zk-smoketest
Browse files Browse the repository at this point in the history
Conflicts:
	zk-smoketest.py
  • Loading branch information
phunt committed Aug 18, 2013
2 parents fd120ee + 8592a04 commit 9a7281b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
24 changes: 19 additions & 5 deletions README.textile
Expand Up @@ -38,11 +38,12 @@ h3. Usage
Usage: zk-smoketest.py [options]

Options:
-h, --help show this help message and exit
--servers=SERVERS comma separated list of host:port (default localhost:2181)
--timeout=TIMEOUT session timeout in milliseconds (default 5000)
-v, --verbose verbose output, include more detail
-q, --quiet quiet output, basically just success/failure
-h, --help show this help message and exit
--servers=SERVERS comma separated list of host:port (default localhost:2181)
--config=CONFIGFILE zookeeper configuration file to lookup servers from
--timeout=TIMEOUT session timeout in milliseconds (default 5000)
-v, --verbose verbose output, include more detail
-q, --quiet quiet output, basically just success/failure
</pre>

The exit code is 0 on success, non-0 exit code on failure.
Expand All @@ -68,6 +69,12 @@ Say you have a ZooKeeper ensemble with 5 servers (host1,host2,host3,host4,host5,
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-smoketest.py --servers "host1:2181,host2:2181,host3:2181,host4:2181,host5:2181"
</code>

or, for a ZK-style configuration file:

<code>
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-smoketest.py --config zk.conf
</code>

h2. zk-latencies.py

This tool uses the ZooKeeper python binding to test various operation latencies. In general the script does the following:
Expand All @@ -92,6 +99,7 @@ Options:
localhost:2181)
--cluster=CLUSTER comma separated list of host:port, test as a cluster,
alternative to --servers
--config=CONFIGFILE zookeeper configuration file to lookup servers from
--timeout=TIMEOUT session timeout in milliseconds (default 5000)
--root_znode=ROOT_ZNODE
root for the test, will be created as part of test
Expand Down Expand Up @@ -133,6 +141,12 @@ Say you have a ZooKeeper ensemble with 5 servers (host1,host2,host3,host4,host5,
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --servers "host1:2181,host2:2181,host3:2181,host4:2181,host5:2181" --znode_count=100 --znode_size=100 --synchronous
</code>

or, for a ZK-style configuration file:

<code>
PYTHONPATH=lib.linux-i686-2.6 LD_LIBRARY_PATH=lib.linux-i686-2.6 ./zk-latencies.py --config zk.conf --znode_count=100 --znode_size=100 --synchronous
</code>

Result:

<pre>
Expand Down
24 changes: 20 additions & 4 deletions zk-latencies.py
Expand Up @@ -28,6 +28,9 @@
default="localhost:2181", help="comma separated list of host:port (default %default), 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("", "--config",
dest="configfile", default=None,
help="zookeeper configuration file to lookup cluster from")
parser.add_option("", "--timeout", dest="timeout", type="int",
default=5000, help="session timeout in milliseconds (default %default)")
parser.add_option("", "--root_znode", dest="root_znode",
Expand Down Expand Up @@ -261,12 +264,25 @@ def func():
"notif %7d watches" % (options.watch_multiple * options.znode_count),
(options.watch_multiple * options.znode_count))

if __name__ == '__main__':
data = options.znode_size * "x"
def read_zk_config(filename):
with open(filename) as f:
config = dict(tuple(line.rstrip().split('=', 1)) for line in f if line.rstrip())
return config

def get_zk_servers(filename):
if options.cluster:
servers = [options.cluster]
return [options.cluster]
elif filename:
config = read_zk_config(options.configfile)
client_port = config['clientPort']
return [",".join("%s:%s" % (v.split(':', 1)[0], client_port)
for k, v in config.items() if k.startswith('server.'))]
else:
servers = options.servers.split(",")
return options.servers.split(",")

if __name__ == '__main__':
data = options.znode_size * "x"
servers = get_zk_servers(options.configfile)

# create all the sessions first to ensure that all servers are
# at least available & quorum has been formed. otw this will
Expand Down
19 changes: 18 additions & 1 deletion zk-smoketest.py
Expand Up @@ -26,6 +26,9 @@
parser = OptionParser(usage=usage)
parser.add_option("", "--servers", dest="servers",
default="localhost:2181", help="comma separated list of host:port (default %default)")
parser.add_option("", "--config",
dest="configfile", default=None,
help="zookeeper configuration file to lookup servers from")
parser.add_option("", "--timeout", dest="timeout", type="int",
default=5000, help="session timeout in milliseconds (default %default)")
parser.add_option("-v", "--verbose",
Expand All @@ -48,8 +51,22 @@ def __str__(self):
return repr(self.value)


def read_zk_config(filename):
with open(filename) as f:
config = dict(tuple(line.rstrip().split('=', 1)) for line in f if line.rstrip())
return config

def get_zk_servers(filename):
if filename:
config = read_zk_config(options.configfile)
client_port = config['clientPort']
return ["%s:%s" % (v.split(':', 1)[0], client_port)
for k, v in config.items() if k.startswith('server.')]
else:
return options.servers.split(",")

if __name__ == '__main__':
servers = options.servers.split(",")
servers = get_zk_servers(options.configfile)

# create all the sessions first to ensure that all servers are
# at least available & quorum has been formed. otw this will
Expand Down

0 comments on commit 9a7281b

Please sign in to comment.