def temp2(): # delete znode_count znodes timer((s.delete(child_path(j)) for j in xrange(options.znode_count)), "deleted %7d permanent znodes " % (options.znode_count)) # create znode_count znodes (ephemeral) timer((s.create(child_path(j), data, zookeeper.EPHEMERAL) for j in xrange(options.znode_count)), "created %7d ephemeral znodes " % (options.znode_count)) # watch znode_count znodes watches = [CountingWatcher() for x in xrange(options.watch_multiple)] def watch(j): for watch in watches: s.exists(child_path(j), watch) timer((watch(j) for j in xrange(options.znode_count)), "watched %7d znodes " % (options.watch_multiple * options.znode_count), options.watch_multiple * options.znode_count) # # delete znode_count znodes timer((s.delete(child_path(j)) for j in xrange(options.znode_count)), "deleted %7d ephemeral znodes " % (options.znode_count)) start = time.time() for watch in watches: if watch.waitForExpected(options.znode_count, 60000) != options.znode_count: raise SmokeError("wrong number of watches: %d" % (watch.count)) print_elap( start, "notif %7d watches" % (options.watch_multiple * options.znode_count), (options.watch_multiple * options.znode_count))
def asynchronous_latency_test(s, data): # create znode_count znodes (perm) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.CreateCallback() cb.cv.acquire() s.acreate(child_path(j), cb, data) callbacks.append(cb) for j, cb in enumerate(callbacks): cb.waitForSuccess() if cb.path != child_path(j): raise SmokeError( "invalid path %s for operation %d on handle %d" % (cb.path, j, cb.handle)) timer2(func, "created %7d permanent znodes " % (options.znode_count)) # set znode_count znodes def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.SetCallback() cb.cv.acquire() s.aset(child_path(j), cb, data) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "set %7d znodes " % (options.znode_count)) # get znode_count znodes def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.GetCallback() cb.cv.acquire() s.aget(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() if cb.value != data: raise SmokeError( "invalid data %s for operation %d on handle %d" % (cb.value, j, cb.handle)) timer2(func, "get %7d znodes " % (options.znode_count)) # delete znode_count znodes (perm) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.DeleteCallback() cb.cv.acquire() s.adelete(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "deleted %7d permanent znodes " % (options.znode_count)) # create znode_count znodes (ephemeral) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.CreateCallback() cb.cv.acquire() s.acreate(child_path(j), cb, data, zookeeper.EPHEMERAL) callbacks.append(cb) for j, cb in enumerate(callbacks): cb.waitForSuccess() if cb.path != child_path(j): raise SmokeError( "invalid path %s for operation %d on handle %d" % (cb.path, j, cb.handle)) timer2(func, "created %7d ephemeral znodes " % (options.znode_count)) watches = [CountingWatcher() for x in xrange(options.watch_multiple)] # watched znode_count znodes def func(): callbacks = [] for watch in watches: for j in xrange(options.znode_count): cb = zkclient.ExistsCallback() cb.cv.acquire() s.aexists(child_path(j), cb, watch) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2( func, "watched %7d znodes " % (options.watch_multiple * options.znode_count), options.watch_multiple * options.znode_count) # delete znode_count znodes (ephemeral) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.DeleteCallback() cb.cv.acquire() s.adelete(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "deleted %7d ephemeral znodes " % (options.znode_count)) start = time.time() for watch in watches: if watch.waitForExpected(options.znode_count, 60000) != options.znode_count: raise SmokeError("wrong number of watches: %d" % (watch.count)) print_elap( start, "notif %7d watches" % (options.watch_multiple * options.znode_count), (options.watch_multiple * options.znode_count))
def __call__(self, handle, typ, state, path): if not self.child_path(self.count) == path: raise ZKClientError("handle %d invalid path order %s" % (handle, path)) CountingWatcher.__call__(self, handle, typ, state, path)
def asynchronous_latency_test(s, data): # create znode_count znodes (perm) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.CreateCallback() cb.cv.acquire() s.acreate(child_path(j), cb, data) callbacks.append(cb) for j, cb in enumerate(callbacks): cb.waitForSuccess() if cb.path != child_path(j): raise SmokeError( "invalid path %s for operation %d on handle %d" % (cb.path, j, cb.handle)) timer2(func, "created %7d permanent znodes " % options.znode_count) # set znode_count znodes def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.SetCallback() cb.cv.acquire() s.aset(child_path(j), cb, data) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "set %7d znodes " % options.znode_count) # get znode_count znodes def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.GetCallback() cb.cv.acquire() s.aget(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() if cb.value != data: raise SmokeError( "invalid data %s for operation %d on handle %d" % (cb.value, j, cb.handle)) timer2(func, "get %7d znodes " % options.znode_count) ZOO_DIGEST_ACL = { "perms": 0x1f, "scheme": "digest", "id": "user:4lo4uMGZQ30s/j5PQ77K8w9AFWs=" } # setACL znode_count znodes def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.DeleteCallback() cb.cv.acquire() s.aset_acl(child_path(j), cb, [ZOO_DIGEST_ACL]) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "setACL %7d znodes " % options.znode_count) # getACL znode_count znodes def func(): callbacks = [] cb = zkclient.DeleteCallback() cb.cv.acquire() s.add_auth("digest", "user:andor", cb) cb.waitForSuccess() for j in xrange(options.znode_count): cb = zkclient.GetCallback() cb.cv.acquire() s.aget_acl(child_path(j), cb) callbacks.append(cb) for j, cb in enumerate(callbacks): cb.waitForSuccess() if len(cb.value) != 1: raise SmokeError( "invalid ACL %s for operation %d on handle %d" % (cb.value, j, cb.handle)) timer2(func, "getACL %7d znodes " % options.znode_count) # delete znode_count znodes (perm) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.DeleteCallback() cb.cv.acquire() s.adelete(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "deleted %7d permanent znodes " % options.znode_count) # create znode_count znodes (ephemeral) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.CreateCallback() cb.cv.acquire() s.acreate(child_path(j), cb, data, zookeeper.EPHEMERAL) callbacks.append(cb) for j, cb in enumerate(callbacks): cb.waitForSuccess() if cb.path != child_path(j): raise SmokeError( "invalid path %s for operation %d on handle %d" % (cb.path, j, cb.handle)) timer2(func, "created %7d ephemeral znodes " % options.znode_count) watches = [CountingWatcher() for x in xrange(options.watch_multiple)] # watched znode_count znodes def func(): callbacks = [] for watch in watches: for j in xrange(options.znode_count): cb = zkclient.ExistsCallback() cb.cv.acquire() s.aexists(child_path(j), cb, watch) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2( func, "watched %7d znodes " % (options.watch_multiple * options.znode_count), options.watch_multiple * options.znode_count) # delete znode_count znodes (ephemeral) def func(): callbacks = [] for j in xrange(options.znode_count): cb = zkclient.DeleteCallback() cb.cv.acquire() s.adelete(child_path(j), cb) callbacks.append(cb) for cb in callbacks: cb.waitForSuccess() timer2(func, "deleted %7d ephemeral znodes " % options.znode_count) start = time.time() for watch in watches: if watch.waitForExpected(options.znode_count, 60000) != options.znode_count: raise SmokeError("wrong number of watches: %d" % watch.count) print_elap( start, "notif %7d watches" % (options.watch_multiple * options.znode_count), (options.watch_multiple * options.znode_count))
def __init__(self, child_path): CountingWatcher.__init__(self) self.child_path = child_path