def compute_func(in_streams, out_streams): merged_stream = Stream('merge of two ntp server offsets') averaged_stream = Stream('sliding window average of offsets') blend(func=lambda x: x, in_streams=in_streams, out_stream=merged_stream) map_window(func=average_of_list, in_stream=merged_stream, out_stream=averaged_stream, window_size=2, step_size=1) stream_to_file(in_stream=averaged_stream, filename='average.dat')
def run_Paxos(): proposers = [ blend(func=proposer_behavior, in_streams=daemons_proposers_out_streams, out_stream=proposer_out_streams[id], state=(id, 0, random_number(), {}), name='proposer_' + str(id)) for id in range(num_proposers) ] acceptors = [ map_element(func=acceptor_behavior, in_stream=daemons_acceptors_out_streams[id], out_stream=acceptor_out_streams[id], state=(id, -1, -1, -1, -1), name='acceptor_' + str(id)) for id in range(num_acceptors) ] time_step_agent = blend(func=time_step_behavior, in_streams=in_streams_for_time_step, out_stream=time_step_stream, state=({}, None), name='time step agent') daemons_acceptors = [ blend(func=delete, in_streams=proposer_out_streams, out_stream=daemons_acceptors_out_streams[id], name='daemons_acceptors_' + str(id)) for id in range(num_acceptors) ] daemons_proposers = [ blend(func=delete, in_streams=acceptor_out_streams, out_stream=daemons_proposers_out_streams[id], name='daemons_proposers_' + str(id)) for id in range(num_proposers) ] #STEP 4. START COMPUTATION # Get the scheduler and execute a step. scheduler = Stream.scheduler # Start the computation by putting a value into the # time step stream time_step_stream.append(('time_step', 1)) # Start the scheduler. scheduler.step()
def compute(in_streams, out_streams): merged_stream = Stream('merge of two ntp server offsets') blend(func=identity, in_streams=in_streams, out_stream=merged_stream) stream_to_file(in_stream=merged_stream, filename='offsets.dat')
def g(in_streams, out_stream, **kwargs): return blend(func, in_streams, out_stream, **kwargs)