I have a barrier implementation, using a PAIR/PAIR
interconnection.
The server side will send a JSON-message to client and then wait for client sending a message. I will send 40000 messages in one test, and I repeat it for 10 times to calculate an average time used.
pair_Server.py
:
import zmq
import random
import sys
import time
context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.bind("tcp://*:5556")
totalTime = 0
for testCount in range(10):
isFirstSend = True
startTime = 0
for num in range(40000):
socket.send_json({ 'num' : num })
if isFirstSend:
isFirstSend = False
startTime = time.time()
msg = socket.recv_json()
totalTime += (time.time() - startTime)
print("Finish test {}".format(testCount))
print(totalTime / 10)
pair_Client.py
:
import zmq
import random
import sys
import time
context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.connect("tcp://localhost:5556")
while True:
msg = socket.recv_json()
socket.send_json(msg)
The output time spend is around 4.3 seconds. I then remove the barrier. Server now will only send JSON-message to client and do not need to wait for the reply. After 10 rounds. The average time spend is 0.3 seconds.
I understand that the speed will become faster but the difference is so big and I would like to ask that if I used a wrong implementation. I have tried PUSH/PULL
sockets for a similar implementation and get a similar result.