def invoke_worker_lambdas(*, load: list, app: str, identifier: str, parent_lambda: str, headers: dict): print(f"Start invoking worker lambdas: {app}") if len(load) == 0: print(f"Load was empty, stopping worker invocations: {app}") return 0, 0, 0 # return futs, timeouts, exceptions to CW metrics load_chunks, chunk_size = _generate_chunked_load(load, chunk_max=100) delay_per_req = _calculate_delays(load_size=len(load)) delays = calculate_delays_between_workers(load_chunks, delay_per_req) delay_random = True delays = make_delays_random(delays) print(f"chunk size: {chunk_size}, # chunks: {len(load_chunks)}") event = { "delay_per_req": delay_per_req, "delay_random": delay_random, "rate": 100, "app": app, "identifier": identifier, "parent_lambda": parent_lambda, "child_lambda": consumer_worker_lambda, "headers": headers, } _invoke_workers(event, load_chunks, delays)
def invoke_slave_lambdas(*, load: list, app: str, identifier: str, parent_lambda: str, headers: dict): print(f'Start invoking slave lambdas: {app}') if len(load) == 0: print(f'Load was empty, stopping slave invocations: {app}') return 0, 0, 0 # return futs, timeouts, exceptions to CW metrics load_chunks, chunk_size = _generate_chunked_load(load, chunk_max=100) delay_per_req = _calculate_delays(load_size=len(load)) delays = calculate_delays_between_slaves(load_chunks, delay_per_req) delay_random = True delays = make_delays_random(delays) print(f'chunk size: {chunk_size}, # chunks: {len(load_chunks)}') event = { 'delay_per_req': delay_per_req, 'delay_random': delay_random, 'rate': 100, 'app': app, 'identifier': identifier, 'parent_lambda': parent_lambda, 'child_lambda': consumer_slave_lambda, 'headers': headers, } _invoke_slaves(event, load_chunks, delays)
def test_calculate_delay_between_workers_random(): load = [1] * 1234 load_chunks, load_size = master._generate_chunked_load(load=load, chunk_max=100) delay_per_req = delay.calculate_delay_per_req( num_total_requests=len(load), total_expected_execution_time=65) delays = delay.calculate_delays_between_workers(load_chunks, delay_per_req) delays_rand = delay.make_delays_random(delays) assert delays[0] != delays_rand[0] and len(delays) == len(delays_rand)