I have the following code taking an array containing 0-100 as values and incrementing those values by one through 200 threads. Question: If I were to build a (leader-follower) distributed system, what aspects of building the system would remain similar to the distributed process I currently have, contained below? What will change moving from the distributed process to a distributed system?
My code follows:
import os if os.name == 'posix': import resource import multiprocessing as mp from multiprocessing import Process, Array, Lock PROCESSES = 200 def add_to_each_element_in_list(l,a): l.acquire() for i in range(len(a)): a[i] += 1 l.release() if __name__ == '__main__': if os.name == 'posix': resource.setrlimit(resource.RLIMIT_NOFILE,(20000, 20000)) arr = Array('i',range(101)) # Create new processes ctx=mp.get_context('spawn') lock=Lock() process_num=0 processList= print("Creating Processes") for process_num in range(PROCESSES): p=ctx.Process(target=add_to_each_element_in_list,args=(lock,arr)) processList.append(p) print("Starting Processes") for p in processList: p.start() print("Waiting for Processes to finish") for p in processList: p.join() #print final list print("Final list: ") print(arr[:])