예제 #1
0
def start_worker(idx):
    print("Starting worker %d" % idx)
    context = zmq.Context()
    res_send_sock = context.socket(zmq.PUB)
    res_send_sock.connect(RESULT_ADDR)

    task_recv_sock = context.socket(zmq.PULL)
    task_recv_sock.connect(TASK_ADDR)

    while True:
        task_msg = task_recv_sock.recv()
        subarray = Task.load(task_msg).subarray
        print("Worker %d doing amazing computation on an array %d long" % (idx, len(subarray)))
        res = Result(idx, sum(subarray))
        res_send_sock.send(res.dump())
        # TODO: check why we always get the same worker do the job
        sleep(randrange(5))
예제 #2
0
def start_worker(idx):
    print("Starting worker %d" % idx)
    context = zmq.Context()
    res_send_sock = context.socket(zmq.PUB)
    res_send_sock.connect(RESULT_ADDR)

    task_recv_sock = context.socket(zmq.PULL)
    task_recv_sock.connect(TASK_ADDR)

    while True:
        task_msg = task_recv_sock.recv()
        subarray = Task.load(task_msg).subarray
        print("Worker %d doing amazing computation on an array %d long" %
              (idx, len(subarray)))
        res = Result(idx, sum(subarray))
        res_send_sock.send(res.dump())
        # TODO: check why we always get the same worker do the job
        sleep(randrange(5))
예제 #3
0
def start_sink(limit):
    print("Starting sink process")
    context = zmq.Context()
    recv_sock = context.socket(zmq.SUB)
    recv_sock.setsockopt(zmq.SUBSCRIBE, '')
    recv_sock.bind(RESULT_ADDR)

    received = 0
    tot_sum = 0

    while received < limit:
        res = Result.load(recv_sock.recv())
        print("Got result %s" % str(res))
        sys.stdout.flush()
        received += 1
        tot_sum += res.result
        print("Received %d packets" % received)

    print("Total sum = %d" % tot_sum)
    sys.stdout.flush()
예제 #4
0
def start_sink(limit):
    print("Starting sink process")
    context = zmq.Context()
    recv_sock = context.socket(zmq.SUB)
    recv_sock.setsockopt(zmq.SUBSCRIBE, '')
    recv_sock.bind(RESULT_ADDR)

    received = 0
    tot_sum = 0

    while received < limit:
        res = Result.load(recv_sock.recv())
        print("Got result %s" % str(res))
        sys.stdout.flush()
        received += 1
        tot_sum += res.result
        print("Received %d packets" % received)

    print("Total sum = %d" % tot_sum)
    sys.stdout.flush()