Beispiel #1
0
from gstlib.zmq.simplemsg import SimpleMessage, TopicMessage
from gstlib.zmq.serializer import SerializerBase, TopicSerializer

###

COUNT = 100000

payload = {'cnt': 1, 'd':datetime.date.today(), 'txt': u'öäüaaa',
           'l': range(10),
           'ids': [ uuid.uuid1() for x in range(5)],
           }
## msg = SimpleMessage(type='öäü', payload=payload)
msg = TopicMessage(topic='öäü', payload=payload)

## s = SerializerBase()
s = TopicSerializer()
## s.multipart = True

# warm-up cpu
for i in xrange(1000000):
    x = float(i) * 0.333
    f = x / 1.1

t0 = time.time()
for n in xrange(COUNT):
    data = s.serialize(msg)
    m = s.deserialize(data)
t1 = time.time()
td = t1 - t0
print "%.6f" % td
tr = (td * 1000000) / COUNT
Beispiel #2
0
except IndexError:
    topic = b''

print repr(url)
print repr(topic)

try:
    zmq_ctx = zmq.Context()

    sin = zmq_ctx.socket(zmq.SUB)
    sin.setsockopt(zmq.SUBSCRIBE, str(topic))
    sin.hwm = 10000
    ## sin.connect(url)
    sin.bind(url)

    ts = TopicSerializer()
    ts.dumps = marshal.dumps
    ts.loads = marshal.loads
    ts.multipart = True

    ## sin.recv()
    ## print 'run'

    while True:
        data = sin.recv_multipart()
        ## pprint(data)
        msg = ts.deserialize(data)
        
except KeyboardInterrupt:
    pass
Beispiel #3
0
    topic = b'x'

print repr(url)
print repr(topic)

gc.disable()

try:
    zmq_ctx = zmq.Context()

    sout = zmq_ctx.socket(zmq.PUB)
    ## sout.setsockopt(zmq.HWM, 20000)
    ## sout.setsockopt(zmq.RATE, 50000000)
    sout.connect(url)

    ts = TopicSerializer()
    ## ts.dumps = msgpack.dumps
    ## ts.loads = msgpack.loads
    ts.dumps = marshal.dumps
    ts.loads = marshal.loads
    ts.multipart = True

    while True:
        msg = TopicMessage(topic=topic, sender=local_ip)
        msg.payload = {b'seq': seq}
        seq += 1
        data = ts.serialize(msg)
        pprint(data)
        sout.send_multipart(data)
        if (seq % 1) == 0:
            ## gc.collect()
Beispiel #4
0
    io_loop = IOLoop.instance()

    sin = zmq_ctx.socket(zmq.SUB)
    sin.setsockopt(zmq.SUBSCRIBE, str(topic))
    sin.setsockopt(zmq.HWM, 0)
    sin.connect(url)

    sout = zmq_ctx.socket(zmq.PUB)
    sout.setsockopt(zmq.HWM, 50000)
    sout.setsockopt(zmq.RATE, 50000000)
    sout.connect(url)

    ## sout.send(b'')

    ts = TopicSerializer()
    ts.dumps = msgpack.dumps
    ts.loads = msgpack.loads
    ts.multipart = False

    chan = Channel(sin, sout, ts)
    proc = Processor()
    proc.add_channel(chan, do_send=False)

    x = PeriodicCallback(sender, 1, io_loop)
    x.start()

    y = PeriodicCallback(proc.print_stat, 1000, io_loop)
    y.start()

    io_loop.start()
Beispiel #5
0
try:
    zmq_ctx = zmq.Context()

    io_loop = IOLoop.instance()

    sin = zmq_ctx.socket(zmq.SUB)
    sin.setsockopt(zmq.SUBSCRIBE, str(topic))
    ## sin.setsockopt(zmq.HWM, 10000)
    sin.connect(url)

    sout = zmq_ctx.socket(zmq.PUB)
    ## sout.setsockopt(zmq.HWM, 1)
    ## sout.setsockopt(zmq.RATE, 100000000)
    sout.connect(url)

    ts = TopicSerializer()
    ## ts.dumps = msgpack.dumps
    ## ts.loads = msgpack.loads
    ts.dumps = marshal.dumps
    ts.loads = marshal.loads
    ts.multipart = False

    chan = Channel(sin, sout, ts)
    proc = Processor()
    proc.add_channel(chan)

    x = PeriodicCallback(proc.print_stat, 1000, io_loop)
    x.start()

    io_loop.start()
except KeyboardInterrupt: