Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process concurrent client requests?

Tags:

python

zeromq

Here is sample code of the request / response pattern with zeroMQ in python. I would like to know if there is way to process requests from multiple clients concurrently?

import zmq 
import time 

def main():
    context = zmq.Context()
    serverSocket = StartServer(context,"9999")
    processRequests(serverSocket)

def processRequests (socket):
    while True:
        print "waiting for request"
        msg = socket.recv()
        print msg
        time.sleep(10)
        socket.send("Request processed")



def StartServer(context, port):
    socket = context.socket(zmq.REP)
    socket.bind("tcp://*:%s" % port)

    print "started server on", port 
    return socket 




if __name__ == '__main__':
    print "starting IPC server"
    main()
like image 716
Milind Torney Avatar asked Sep 14 '13 18:09

Milind Torney


People also ask

What is concurrent client request?

Updated at: 2022-09-15 GMT+08:00. The number of concurrent requests refers to the number of requests that the system can process simultaneously.

How do I send a concurrent request?

- [Narrator] Concurrent requests is the ability for us to send multiple requests. We do this by taking advantage of the asynchronous request and basically creating an array of promises that we can then execute, and this provides us multiple concurrent requests.

How do you handle concurrent requests in C#?

How to handle concurrency in ASP.NET Core Web API. Create an empty project and update the Startup class to add services and middleware for MVC. Add a controller with GET and PUT to demonstrate concurrency. Send a GET request and observe the ETag header (using Postman).


1 Answers

The REQ-REP pattern is a synchronous pattern. If there are two REQ sockets connected to the same REP socket, the REP socket will process requests serially.

If you want to do asynchronous request-reply, you'll want to look into the ROUTER-DEALER pattern, which is the generalized analogue of REQ-REP.

If you want a brokered asynchronous request-reply, look at the "Figure 16 - Extended Request-Reply" section here.

like image 183
Timothy Shields Avatar answered Oct 10 '22 02:10

Timothy Shields