开发者

ØMQ multithreaded REQ/REP

I'm trying to write an application that will allow the user to start long-running calculation processes which will receive commands from a web server using ØMQ. I use standart request-reply architecture: server has a REQ socket connected to a worker process开发者_如何学JAVAes REP socket. When a new command is received from a user, it is sent to the worker process:

self.instance_dict[instance_id].socket.send(json_command)
result = self.instance_dict[instance_id].socket.recv()

The problem appears when the second command is sent while the first one is still being executed. Does ØMQ provide functionality that will take care of message queues or do I have ot implement it myself? Or should I change the architecture?


For REQ/REP, the second command must not be sent until the first one has been acknowledged; ZMQ enforces the correct ordering of messages in the protocol.

You might want to use PUSH/PULL instead - the messages will then be queued up automatically without requiring replies in between (as an aside, I think this also automatically allows you to use multiple workers for scaling and load balancing).

If you use an IOLoop, you can set up ZMQStreams that will queue up messages within a process. See https://github.com/zeromq/pyzmq/blob/master/zmq/eventloop/ioloop.py

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜