예제 #1
0
def main():
    print "\nThis program will calculate Prime Factorials of a bunch of random numbers."
    print "The more workers you will start (on different cpus/cores/machines),"
    print "the faster you will get the complete list of results!\n"
    dispatcher = Pyro.core.getProxyForURI(
        "PYRONAME://:Distributed2.dispatcher")
    print "placing work items into dispatcher queue."
    for i in range(NUMBER_OF_ITEMS):
        number = random.randint(3211, 5000) * random.randint(177, 3000) * 37
        numbers[number] = None
        item = Workitem(i + 1, number)
        dispatcher.putWork(item)
    print "getting results from dispatcher queue."
    resultCount = 0
    while resultCount < NUMBER_OF_ITEMS:
        try:
            item = dispatcher.getResult()
            processResult(item)
            resultCount += 1
        except Queue.Empty:
            print "No results available yet. Work queue size:", dispatcher.workQueueSize(
            )

    if dispatcher.resultQueueSize() > 0:
        print "removing leftover results from the dispatcher"
        while True:
            try:
                item = dispatcher.getResult()
                processResult(item)
            except Queue.Empty:
                break

    print "\nComputed Prime Factorials follow:"
    for (number, factorials) in numbers.items():
        print number, "-->", factorials
예제 #2
0
def placeWork(dispatcher, numbers):
    print("\nPlacing work items into dispatcher queue")
    for i in range(len(numbers)):
        item = Workitem(i + 1, numbers[i], CLIENTNAME)
        success = False
        while not success:
            try:
                dispatcher.putWork(item)
                success = True
            except Exception:
                print("connection lost. reconnecting...")
예제 #3
0
def placework(dispatcher):
    print("placing work items into dispatcher queue.")
    for i in range(NUMBER_OF_ITEMS):
        if sys.version_info < (3, 0):
            # python 2.x range arguments needs to be within C int range
            number = random.randint(3211, 12000) * random.randint(3211, 11000)
        else:
            # python 3.x allows arbitrary size range
            number = random.randint(3211, 4999999) * random.randint(
                3211, 999999)
        item = Workitem(i + 1, number)
        dispatcher.putWork(item)
예제 #4
0
def addToQueue():

	# Fetch get variables
	filePaths = json.loads(request.form.get("files"))
	filesShort = json.loads(request.form.get("filesShort"))
	outputPath = request.form.get("outputPath")

	current_id = 0

	# Read max_id from file
	with open("config/max_id.json","r") as f:
		current_id = int(json.loads(f.read())["id"])

	# Get reference to the dispatcher	
	with Pyro4.core.Proxy("PYRONAME:"+defaultNameServer+"@"+ip) as dispatcher:
		# Prepare the items and add to queue
		for path,pathShort in zip(filePaths,filesShort):
			current_id+=1
			filename = pathShort.split(".")[0]
			outPath = outputPath + "/" + filename + ".tif"
			print filename
			print outputPath
			item = Workitem(current_id, path, outPath)
			dispatcher.putWork(item)

	# Update max id
	with open("config/max_id.json","w") as f:	
		f.write(json.dumps({"id":str(current_id)}))

	# Get the current queue	
	queue = pickle.load(open("config/work_queue.p","rb"))
	
	# Prepare the response
	dictQueue = []
	for key,val in queue.items():
		dictQueue.append({"itemId":val.itemId,"path":val.path,"output_path":val.output_path,"worker_id":val.worker_id,"start_time":val.start_time,"end_time":val.end_time})
		
	ordered = sorted(dictQueue, key=lambda k:k["itemId"])

	# Send to page
	return jsonify({"success":"true","queue":ordered})
예제 #5
0
def placeWork(master, numbers):
    print("\nPlacing work items into master queue")
    for i in range(len(numbers)):
        item = Workitem(i + 1, numbers[i])
        master.putWork(item)
예제 #6
0
def placeWork(dispatcher, numbers):
    print("\nPlacing work items into dispatcher queue")
    for i in range(len(numbers)):
        item = Workitem(i + 1, numbers[i])
        item.assignedBy = CLIENTNAME
        dispatcher.putWork(item)
예제 #7
0
def placework(dispatcher):
    print("placing work items into dispatcher queue.")
    for i in range(NUMBER_OF_ITEMS):
        number = random.randint(3211, 5000) * random.randint(177, 3000) * 37
        item = Workitem(i + 1, number)
        dispatcher.putWork(item)