Esempio n. 1
0
def do_load(args):
    print "Do load"
    with open(args.filename) as fd:
        batches = batch_pb2.BatchList()
        batches.ParseFromString(fd.read())

    stream = Stream(args.url)
    stream.connect()

    futures = []
    start = time.time()

    for batch_list in _split_batch_list(batches):
        future = stream.send(message_type='system/load',
                             content=batch_list.SerializeToString())
        futures.append(future)

    for future in futures:
        result = future.result()
        assert (result.message_type == 'system/load-response')

    stop = time.time()
    print "batches: {} batch/sec: {}".format(
        str(len(batches.batches)),
        len(batches.batches) / (stop - start))

    stream.close()
Esempio n. 2
0
def do_load(args):
    print "Do load"
    with open(args.filename) as fd:
        batches = batch_pb2.BatchList()
        batches.ParseFromString(fd.read())

    stream = Stream(args.url)
    stream.connect()

    futures = []
    start = time.time()

    for batch_list in _split_batch_list(batches):
        future = stream.send(
            message_type='system/load',
            content=batch_list.SerializeToString())
        futures.append(future)

    for future in futures:
        result = future.result()
        assert(result.message_type == 'system/load-response')

    stop = time.time()
    print "batches: {} batch/sec: {}".format(
        str(len(batches.batches)),
        len(batches.batches) / (stop - start))

    stream.close()
Esempio n. 3
0
class TransactionProcessor(object):
    def __init__(self, url):
        self._stream = Stream(url)
        self._handlers = []

    def add_handler(self, handler):
        self._handlers.append(handler)

    def start(self):
        self._stream.connect()

        futures = []
        for handler in self._handlers:
            for version in handler.family_versions:
                for encoding in handler.encodings:
                    future = self._stream.send(
                        message_type='tp/register',
                        content=TransactionProcessorRegisterRequest(
                            family=handler.family_name,
                            version=version,
                            encoding=encoding,
                            namespaces=handler.namespaces).SerializeToString())
                    futures.append(future)

        for future in futures:
            LOGGER.info("future result: %s", repr(future.result))

        while True:
            msg = self._stream.receive()
            LOGGER.info("received %s", msg.message_type)

            request = TransactionProcessRequest()
            request.ParseFromString(msg.content)
            state = State(self._stream, request.context_id)

            try:
                self._handlers[0].apply(request, state)
                self._stream.send_back(message_type=MessageType.TP_RESPONSE,
                                       correlation_id=msg.correlation_id,
                                       content=TransactionProcessResponse(
                                           status=TransactionProcessResponse.OK
                                       ).SerializeToString())
            except InvalidTransaction as it:
                LOGGER.warning("Invalid Transaction %s", it)
                self._stream.send_back(
                    message_type=MessageType.TP_RESPONSE,
                    correlation_id=msg.correlation_id,
                    content=TransactionProcessResponse(
                        status=TransactionProcessResponse.INVALID_TRANSACTION).
                    SerializeToString())
            except InternalError as ie:
                LOGGER.warning("State Error! %s", ie)
                self._stream.send_back(message_type=MessageType.TP_RESPONSE,
                                       correlation_id=msg.correlation_id,
                                       content=TransactionProcessResponse(
                                           status=TransactionProcessResponse.
                                           INTERNAL_ERROR).SerializeToString())