pyzmq icon indicating copy to clipboard operation
pyzmq copied to clipboard

Throughput Varies for Different Message with Same Length

Open Kipsora opened this issue 6 years ago • 0 comments

I've use ROUTER - DEALER pattern to transfer messages between two machine. However, it seems that the throughput of zeromq socket varies with different message with same length. Attached below are my codes, experimented on python3 on OSX Mojave 10.14 (client) and Ubuntu 16.04 LTS(server):

# server.py
import zmq

if __name__ == '__main__':
    with zmq.Context() as context:
        with context.socket(zmq.ROUTER) as socket:
            socket.bind('tcp://*:10009')
            identity, *message = socket.recv_multipart(copy=False)
            # When I change '*' to 'a' or any other alphabet character the 
            # socket slows down (12 MB/s -> 1MB/s)
            socket.send_multipart((identity, b'*' * 1024 * 1024 * 50), copy=False)
# client.py
import zmq

if __name__ == '__main__':
    with zmq.Context() as context:
        with context.socket(zmq.DEALER) as socket:
            socket.connect('tcp://<remote machine address>:10009')
            socket.send(b'')
            print(len(socket.recv_multipart(copy=False)[0]))

Kipsora avatar Oct 12 '18 06:10 Kipsora