def get_test(procs, ops, storage_url, token, container_name, size): print "Starting GETs %s procs %s ops, %sk of data" % (procs, ops, size) prefix = "%s%s%s" % (procs, ops, size) get_threads = [] objs = [o["name"] for o in client.get_container(storage_url, token, container_name, prefix=prefix)[1]] start_get = time.time() for i in range(procs): t = GetClass(i, ops, storage_url, token, container_name, objs) t.start() get_threads.append(t) [t.join() for t in get_threads] end_get = time.time() return str(end_get - start_get)
threading.Thread.__init__(self) self.objs = objs self.c = c self.url = url self.token = token self.name = n print "init thread %s, deleting %s objects from %s" % (n, len(objs), c) def run(self): for o in self.objs: try: client.delete_object(self.url, self.token, self.c, o) except client.ClientException as e: print "** ERROR ** %s: %s" % (e.http_status, e.http_reason) if __name__ == "__main__": auth_url = "https://auth.api.rackspacecloud.com/v1.0" storage_url, token = client.get_auth(auth_url, os.environ['CF_USER'], os.environ['CF_KEY']) containers = [(c['name'], c['count']) for c in client.get_account(storage_url, token, prefix="cf_speed_test")[1]] for c in containers: if int(c[1]) > 0: objs = [o['name'] for o in client.get_container(storage_url, token, c[0])[1]] for x in range(20): d = DeleteClass(x+1, storage_url, token, c[0], objs[x::20]) d.start() else: print "ok to delete container %s" % c[0] client.delete_container(storage_url, token, c[0])
from optparse import OptionParser parser = OptionParser() parser.add_option("-t", "--threads", dest="threads", type="int", default=5, help="number of threads") parser.add_option("-o", "--ops", dest="ops", type="int", default=10, help="number of operations per thread") parser.add_option("-s", "--size", dest="size", type="int", default=32, help="size of object in kB") parser.add_option("--no-get", dest="no_get", action="store_false", default=True, help="skip get") (options, args) = parser.parse_args(sys.argv) auth_url = "https://auth.api.rackspacecloud.com/v1.0" storage_url, token = client.get_auth(auth_url, os.environ["CF_USER"], os.environ["CF_KEY"]) c = "cf_speed_test_%s" % str(random.random()) try: client.get_container(storage_url, token, c) except client.ClientException, e: if e.http_status == 404: client.put_container(storage_url, token, c) fp = open("/dev/random", "r") data = fp.read(options.size * 1024) fp.close() fp = open("errors.txt", "a") fp.write("new test %s\n" % c) fp.close() print "testing with container %s" % c stats = [options.threads, options.ops, options.size, storage_url, c]