Exemplo n.º 1
0
def worker_thread(workernum, context=None):
    context = context or zmq.Context.instance()
    worker = context.socket(zmq.REQ)

    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("tcp://10.66.137.191:5588")

    total = 0
    while True:
        # Tell the router we're ready for work
        worker.send(b"ready")

        # Get workload from router, until finished
        workload = worker.recv()
        finished = workload == b"END"
        if finished:
            print "this is worker %s, Processed: %d tasks" % (workernum + 1, total)
            break
        else:
            print "\nI need sleep %ss on %s" % (6-(int(workload) + 1), workernum + 1)
            time.sleep(6-(int(workload) + 1))
        total += 1

        # Do some random work
        time.sleep(0.1 * random.random())
Exemplo n.º 2
0
    def worker_thread(self, worker_index, context):
        w = context.socket(zmq.REQ)
        zhelpers.set_id(w)
        w.connect(self.thread_endpoint)

        initfn = getattr(self, 'init_thread', None)
        if initfn and callable(initfn):
            initfn(worker_index = worker_index)


        while True:
            w.send(messages.create_ready())

            msg = w.recv()
            data, tt, msgtype = messages.get(msg)

            assert tt == self.task_type

            if msgtype == messages.MESSAGE_TYPE_END:
                break

            data = data or {}
            sdata = self.handle_thread_execution(data = data, index = worker_index)
            if sdata:
                data.update(sdata)
            smsg = messages.create_data(self.task_type, data)
            self.sender.send(smsg)
def tagWorker(workerID, routerAddr, resQ, secret, public, blockSize):

    bW = {}
    bT = {}
    bTimer = ExpTimer()

    workerName = mp.current_process().name
    bTimer.registerSession(workerName)
    bTimer.registerTimer(workerName, "tag")

    reqSocket = zmq.Context().socket(zmq.REQ)
    zhelpers.set_id(reqSocket)
    reqSocket.connect(routerAddr)

    print "Worker", workerName, "initiated"
    total = 0

    while True:
        reqSocket.send(b"ready")
        blockPB = reqSocket.recv()
        if blockPB == b"END":
            totalTagTime = bTimer.getTotalTimer(workerName, "tag")
            workerResults = cPickle.dumps(
                [workerName, bW, bT, totalTagTime, total])
            resQ.put(workerResults)
            break
        else:
            total += 1
            block = be.BlockDisk2Block(blockPB, blockSize)
            bIndex = block.getDecimalIndex()
            bTimer.startTimer(workerName, "tag")
            bW[bIndex] = singleW(block, secret["u"])
            bT[bIndex] = singleTag(bW[bIndex], block, public["g"], secret["d"],
                                   public["n"])
            bTimer.endTimer(workerName, "tag")
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        self.context = zmq.Context()
        print 'worker will send to collector endpoint: %s' % self.collector_endpoint
        self.sender = self.context.socket(zmq.PUSH)
        self.sender.connect(self.collector_endpoint)

        print 'worker connecting to endpoint %s' % self.endpoint
        self.worker = self.context.socket(zmq.REQ)
        zhelpers.set_id(self.worker)
        self.worker.connect(self.endpoint)

        print 'worker id: %s' % self.worker.getsockopt(zmq.IDENTITY)
Exemplo n.º 5
0
    def __init__(self, endpoint_address, task_type = '', id_prefix = 'client'):
        """
        Instantiates a sevice client.

        :param EndpointAddress endpoint_address: Address of the service broker's frontend
        :param TaskType task_type: A registered task type or a blank string. Can be overridden in the request
        :param str id_prefix: A prefix for the id of the client, useful for debugging
        :return: A ServiceClient instance
        """

        if not endpoint_address:
            raise TypeError('Must supply an endpoint address')

        if not isinstance(endpoint_address, EndpointAddress):
            endpoint_address = EndpointAddress(endpoint_address)

        self.task_type = ''
        if task_type:
            if not isinstance(task_type, TaskType):
                raise TypeError('task_type is required to be a TaskType enumerated value')

            self.task_type = task_type

        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REQ)
        self.client_id = zhelpers.set_id(self.socket, prefix=id_prefix)
        logger.debug('Client id: %s', self.client_id)

        if endpoint_address:
            self.endpoint = EndpointAddress(endpoint_address)

        logger.info('Client connecting to endpoint: %s', endpoint_address)
        self.socket.connect(self.endpoint)
Exemplo n.º 6
0
def worker_thread(context=None):
    context = context or zmq.Context()
    worker = context.socket(zmq.REQ)

    zhelpers.set_id(worker)
    worker.connect("tcp://127.0.0.1:5671")

    total = 0
    while True:
        worker.send(b"ready")
        workload = worker.recv()
        finished = workload == b"END"
        if finished:
            print("Process: %d tasks" % total)
            break
        total += 1

        time.sleep(0.1 * random.random())
Exemplo n.º 7
0
def worker_thread(context=None):
    context = context or zmq.Context.instance()
    worker = context.socket(zmq.REQ)

    zhelpers.set_id(worker)
    worker.connect("tcp://localhost:5671")

    total = 0
    while True:
        worker.send(b"ready")

        workload = worker.recv()
        finished = workload == b"END"
        if finished:
            print("Processed: %d tasks" % total)
            break
        total += 1

        time.sleep(0.1 * random.random())
Exemplo n.º 8
0
def worker_task(id, context=None):
    context = context or Context.instance()
    worker = context.socket(zmq.REQ)
    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("tcp://localhost:5671")
    total = 0
    while True:
        # Tell the router we're ready for work
        yield from worker.send(b"ready")
        # Get workload from router, until finished
        workload = yield from worker.recv()
        #print('worker {} received: {}'.format(id, workload))
        finished = workload == b"END"
        if finished:
            print("worker %d processed: %d tasks" % (id, total))
            break
        total += 1
        # Do some random work
        yield from asyncio.sleep(0.1 * random.random())
    return ('worker {}'.format(id), total)
Exemplo n.º 9
0
def worker_task(id, context=None):
    context = context or Context.instance()
    worker = context.socket(zmq.REQ)
    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("tcp://localhost:5671")
    total = 0
    while True:
        # Tell the router we're ready for work
        yield worker.send(b"ready")
        # Get workload from router, until finished
        workload = yield worker.recv()
        #print('(worker {}) received: {}'.format(id, workload))
        finished = workload == b"END"
        if finished:
            print("worker %d processed: %d tasks" % (id, total))
            break
        total += 1
        # Do some random work
        yield gen.sleep(0.1 * random.random())
    raise gen.Return(('worker {}'.format(id), total))
Exemplo n.º 10
0
def worker_thread(context):
    worker = context.socket(zmq.REQ)

    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("ipc://routing.ipc")

    total = 0
    while True:
        # Tell the router we're ready for work
        worker.send("ready")

        # Get workload from router, until finished
        workload = worker.recv()
        finished = workload == "END"
        if finished:
            print "Processed: %d tasks" % total
            break
        total += 1

        # Do some random work
        time.sleep(random.random() / 10 + 10**-9)
Exemplo n.º 11
0
Arquivo: rtmama.py Projeto: tmc/zguide
def worker_thread(context):
    worker = context.socket(zmq.REQ)

    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("ipc://routing.ipc")

    total = 0
    while True:
        # Tell the router we're ready for work
        worker.send("ready")

        # Get workload from router, until finished
        workload = worker.recv()
        finished = workload == "END"
        if finished:
            print "Processed: %d tasks" % total
            break
        total += 1

        # Do some random work
        time.sleep(random.random() / 10 + 10 ** -9)
Exemplo n.º 12
0
def worker_thread(context=None):
    context = context or zmq.Context.instance()
    worker = context.socket(zmq.REQ)

    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("ipc://routing.ipc")

    total = 0
    while True:
        # Tell the router we're ready for work
        worker.send(b"ready")

        # Get workload from router, until finished
        workload = worker.recv()
        finished = workload == b"END"
        if finished:
            print("Processed: %d tasks" % total)
            break
        total += 1

        # Do some random work
        time.sleep(0.1 * random.random())
Exemplo n.º 13
0
def worker_thread(context=None):
    context = context or zmq.Context.instance()
    worker = context.socket(zmq.REQ)

    # We use a string identity for ease here
    zhelpers.set_id(worker)
    worker.connect("tcp://localhost:5671")

    total = 0
    while True:
        # Tell the router we're ready for work
        worker.send(b"ready")

        # Get workload from router, until finished
        workload = worker.recv()
        finished = workload == b"END"
        if finished:
            print("Processed: %d tasks" % total)
            break
        total += 1

        # Do some random work
        time.sleep(0.1 * random.random())
Exemplo n.º 14
0
 def __init__(self):
     self.context = zmq.Context()
     self.worker = self.context.socket(zmq.REQ)
     zhelpers.set_id(self.worker)
     self.worker.connect(self.endpoint)
Exemplo n.º 15
0
    
    for i in range(len(matrizA)):
        for j in range(len(matrizB[0])):
            for k in range(len(matrizB)):
                matrizR[i][j] += matrizA[i][k] * matrizB[k][j]
    #matriz = matrizR.tolist()
    return matrizR


NBR_WORKERS = 2

context = zmq.Context.instance()
worker = context.socket(zmq.REQ)
matrizR = None
# We use a string identity for ease here
zhelpers.set_id(worker)
worker.connect("tcp://localhost:5671")

total = 0

while True:
    # Tell the router we're ready for work
    if total == 0:
        worker.send(b"ready")
    else :
        matriz_json = matrizR.tolist()
        matriz_json = json.dumps(matriz_json)
        print(matrizR)
        worker.send(matriz_json.encode())

    # Get workload from router, until finished