English 中文(简体)
零MQ有选择性的共和国/次模式?
原标题:ZeroMQ selective pub/sub pattern?

I m试图为N前端服务器和M后端工人设计零MQ架构,前端服务器将任务交给后继服务器。 前端服务器确实有关于后端服务器的信息,但后端服务器不知道前端。 我有两类任务,一类是使用圆筒,只使用一个后端服务器,而另一种则应当向所有后端服务器播放。 我不想有一个中央经纪人,因为这将是一个失败点。

第一类任务要求/答复模式似乎是正确的,第二类是出版商/订阅商。 但是,两者结合的模式如何? 如果我想向所有服务器发出电文或仅向一台随机后端服务器发送电文,那么是否有任何赞助者允许我及时选择?

The solution I ve come up with is just use publisher/subscriber and prepend messages with back-end server ID and some magic value if it s addressed to all. However, this would create lot unnecessary traffic. Is there cleaner and more efficient way to do it?

问题回答

我认为唯一的可能性是使用DEALER-ROUTER组合。 DEALER at the frontend, ROUTER at the Backend. 每个前线服务器应包含每个后台服务器(供广播)的DEALER袖珍材料和一台DEALER与所有后台服务器连接的上表,一度是圆顶。 现在让我解释为什么。

  1. You can t really use PUB-SUB in such a critical case, because that pattern can very easily drop messages silently, it does not queue. So in fact the message posted to PUB can arrive to any subset of SUB since it s (dis)connecting in the background. For this reason you need to simulate broadcast by looping over DEALER sockets assigned to all the background servers. It will queue messages if the backend part is not connected, but beware of the HWM. The only final solution is to use heartbeat to know when a backend is dead and destroy the socket assigned to it.
  2. A ROUTER socket at the background is a logical solution since you can asynchronously accept any number of requests and since it s a ROUTER socket it is super easy to send the response back to the frontend that requested the task. By having a single ROUTER in the background servers you can make it in a way that they are not even aware of the fact that there is a broadcast happening, they see everything as a direct request to them. Broadcasting is purely a frontend thing. The only issue with this solution might be that if your backend server is not fast enough, all the frontend servers may fill it up so that it reaches the HWM and starts dropping the packages. You can prevent this by having more threads/processes processing the messages from the ROUTER socket. zmq_proxy() is a useful function for this stuff.

希望:





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签