def main(): path = None if len(sys.argv) >= 2: path = sys.argv[1] backend = cos.Backend(pywren_config['ibm_cos'], pywren_config['pywren']['storage_bucket']) pw = pywren.ibm_cf_executor(config=pywren_config) if path == None: execute(pw, backend, N_SLAVES, MASTER_DELAY, SLAVES_DELAY) return num_slaves = N_SLAVES num_samples = N_SAMPLES if len(sys.argv) >= 3: num_slaves = int(sys.argv[2]) if len(sys.argv) >= 4: num_samples = int(sys.argv[3]) with open(path, "w") as f: f.write("slaves,time\n") for slaves in range(1, num_slaves + 1, int(num_slaves / num_samples)): correct, execution_time = execute(pw, backend, slaves, MASTER_DELAY, SLAVES_DELAY) print(slaves, getRequests(backend)) if not correct: print("ERROR: Incorrect execution sequence", file=sys.stderr) exit(1) f.write("{},{}\n".format(slaves, execution_time))
def slave(id, x, buck, ibm_cos): backend = cos.Backend(ibm_cos, buck) backend.put_object('p_write_{}'.format(id), '') while not backend.exist_object('write_{}'.format(id)): time.sleep(x) t1 = time.time() idStr = '{}\n'.format(id) contents = backend.get_object('result.txt', False).decode('utf-8') if len(contents) == 0 or '\n' + idStr not in contents: contents += idStr backend.put_object('result.txt', contents) t2 = time.time() print(t2 - t1, 's')
def master(id, x, buck, ibm_cos): write_permission_list = [] backend = cos.Backend(ibm_cos, buck) x = max(x, 0.01) backend.put_object('result.txt', b'') updated = backend.get_etag('result.txt') time.sleep(x) requests = getRequests(backend) while len(requests) > 0: request = requests.pop(0) tmp = backend.get_etag('result.txt') backend.delete_object('p_write_{}'.format(request)) write_permission_list.append(request) backend.put_object('write_{}'.format(request), '') timeoutCounter = 0 while tmp == updated: print("Wait") time.sleep(x) tmp = backend.get_etag('result.txt') timeoutCounter += 1 if timeoutCounter > 200: write_permission_list.append(-1) return write_permission_list updated = tmp backend.delete_object('write_{}'.format(request)) time.sleep(x) requests = getRequests(backend) return write_permission_list
#! /usr/bin/env python3 import cos cos_config = { 'endpoint': '', 'secret_key': '', 'access_key': '', 'api_key': '', 'private_endpoint': '' } back = cos.Backend(cos_config, 'test-buck-urv') for obj in back.list_objects('p_write_'): print("Removing:", obj['Key']) back.delete_object(obj['Key']) for obj in back.list_objects('write_'): print("Removing:", obj['Key']) back.delete_object(obj['Key']) back.delete_object('result.txt')