[zeromq-dev] Hi All

Bhanu Chouhan bhanupratapsinghchouhan88 at gmail.com
Mon Dec 2 18:49:32 CET 2013


Hi All,

I have tried some request and reply example.

I have written a simple server and client in BSD sockets. In which server
(file_bsd_ser.py) binary read a file requested from client
(file_bsd_req.py) and send it to client in chunks.

I have done the same using ZMQ REQ & REP sockets in filerepexp.py (server)
and filereqexp.py (client).

The file i have chosen was of 50 MB.

The task is taking almost double time in case of ZMQ, but it should not be
the case.

Please please please help me on above query that why ZMQ taking more time.
Actually it is required for my project on ZMQ study.


regards,
Bhanu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131202/1d402e88/attachment.htm>
-------------- next part --------------
import socket
import sys
import time

CHUNK_SIZE = 1024

s = socket.socket()
s.connect(("localhost",9999))

start = time.time()

print "requesting file::>"
s.send("abc.rar");
msg = s.recv(1024);
print "processing :: ", msg
run = True
file1 = open("abcd1.rar","a")
while run:
    s.send("fetch");
    message = s.recv(2000)

    if(len(message)<CHUNK_SIZE):
    
        run = False
        print len(message)
    file1.write(message)
    print "chunk written" , len(message)
    
end = time.time()

print "done"

time_taken = end-start

print "time taken", time_taken

s.close()
file1.close()



-------------- next part --------------
import socket
import sys

CHUNK_SIZE = 1024

s = socket.socket()
s.bind(("localhost",9999))

print "waiting for user::>"
s.listen(10) 
sc, address = s.accept()

#run1 = True

#socket.send("fetch","abc");
#while run1:
msg = sc.recv(1024)
file1 = open(msg,"rb")
sc.send("ok")
run2 = True
while run2:
    sc.recv(1024)
    message = file1.read(CHUNK_SIZE)
    if(len(message)<CHUNK_SIZE):
        run2 = False
    sc.send(message)
    print len(message)
print "done"
 #   run1 = False

sc.close()
file1.close()
-------------- next part --------------


import zmq
import time

context = zmq.Context()

CHUNK_SIZE = 1024


socket = context.socket(zmq.REP)
socket.bind ("tcp://*:5555")
print "waiting for user::>"
#socket.send("fetch","abc");
#run1 = True 
#while run1:
msg = socket.recv()
file1 = open(msg,"rb")
socket.send("ok")
run2 = True
while run2:
    socket.recv()
    message = file1.read(CHUNK_SIZE)
    if(len(message)<CHUNK_SIZE):
        run2 = False
    socket.send(message)
    print len(message)
print "done"
#run1 = False


socket.close()
file1.close()
-------------- next part --------------

import zmq
import time

context = zmq.Context()

CHUNK_SIZE = 1024


socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:5555")

start = time.time()

print "requesting file::>"
socket.send("abc.rar");
msg = socket.recv();
print "processing :: ", msg
run = True
file1 = open("abcd.rar","a")
while run:
    socket.send("fetch");
    message = socket.recv()
    if(len(message)<CHUNK_SIZE):
        run = False
        print len(message)
    file1.write(message)
    print "chunk written", len(message)

end = time.time()

print "done"

time_taken = end-start

print "time taken", time_taken

socket.close()
file1.close()


More information about the zeromq-dev mailing list