简体   繁体   English

使用IPC,Twisted或ZeroMQ的架构方法?

[英]Architecture approach with IPC, Twisted or ZeroMQ?

I'm using twisted to get messages from internet connected sensors in order to store it to a db. 我正在使用twisted来从互联网连接的传感器获取消息,以便将其存储到数据库中。
I want to check these messages without interfere these process,because I need compare every message with some base values at db, if some is matched I need trigger an alert for this, and the idea is not block any process... 我想在不干扰这些过程的情况下检查这些消息,因为我需要在db处比较每条消息和一些基本值,如果有一些匹配,我需要触发一个警报,并且这个想法不会阻止任何进程......

My Idea is create a new process to check and alert, but I need after the first process store the message, it will send the message to the new process in order to check and alert if is required. 我的想法是创建一个新的流程来检查和提醒,但我需要在第一个流程存储消息后,它会将消息发送到新流程,以便检查并提醒是否需要。

I'm need IPC for this, and I was thinking to use ZeroMQ, but also twisted have a approach to work with IPC, I think if I use ZeroMQ, but maybe it will be self-defeating... 我需要IPC才能做到这一点,而我正在考虑使用ZeroMQ,但也有扭曲的方法与IPC合作,我想如果我使用ZeroMQ,但也许它会弄巧成拙......

What think you about my approach? 你怎么看待我的做法? Maybe I'm completely wrong at all? 也许我完全错了?

Any advice are welcome.. Thanks 欢迎任何建议..谢谢

PD:This Process will run at a dedicated server, with a expected load of 6000 msg/hour of 1Kb each one PD:此进程将在专用服务器上运行,预期负载为6000 msg /小时,每个1Kb

All of these approaches are possible. 所有这些方法都是可能的。 I can only speak abstractly because I don't know the precise contours of your application. 我只能抽象地说话,因为我不知道你的应用程序的精确轮廓。

If you already have a working application but it just isn't fast enough to handle the number of messages you throw at it, then identify the bottleneck. 如果您已经有一个正在运行的应用程序,但它不够快,无法处理您抛出的消息数,那么就找出瓶颈。 The two likely causes of your holdup are DB access or alert-triggering because either one of these are probably synchronous IO operations. 您持有的两个可能原因是数据库访问或警报触发,因为其中任何一个都可能是同步IO操作。

How you deal with this depends on your workload: 您如何处理这取决于您的工作量:

  1. If your message rate is high and constant, then you need to make sure your database can handle this rate. 如果您的消息率很高并且不变,那么您需要确保您的数据库可以处理此速率。 If your DB can't handle it, then no amount of non-blocking message passing will help you! 如果您的数据库无法处理它,那么没有任何非阻塞消息传递将帮助您! In this order: 按此顺序:
    1. Try tuning your database. 尝试调整您的数据库。
    2. Try putting your database on a bigger comp with more memory. 尝试将数据库放在具有更多内存的更大的comp上。
    3. Try sharding your database across multiple machines to distribute the workload. 尝试在多台计算机上分割数据库以分配工作负载。 Once you know your db can handle the message rate, you can deal with other bottlenecks using other forms of parallelism. 一旦您知道数据库可以处理消息速率,您就可以使用其他形式的并行处理其他瓶颈。
  2. If your message rate is bursty then you can use queueing to handle the bursts. 如果您的消息速率是突发性的,那么您可以使用排队来处理突发。 In this order: 按此顺序:
    1. Put a load balancer in front of a cluster of message processors. 将负载均衡器放在消息处理器集群的前面。 All this balancer should do is redistribute sensor messages to different machines for check-and-alert processing. 所有这些平衡器应该做的是将传感器消息重新分配到不同的机器以进行检查和警报处理。 The advantage of this approach is that you will probably not need to change your existing application, just run it on more machines. 这种方法的优点是您可能不需要更改现有应用程序,只需在更多计算机上运行它。 This works best if your load balancer does not need to wait for a response, just forward the message. 如果您的负载均衡器不需要等待响应,则最有效,只需转发消息即可。
    2. If your communication needs are more complex or are bidirectional, you can use a message bus (such as ZeroMQ) as the communication layer between message-processors, alert-senders, and database-checkers. 如果您的通信需求更复杂或是双向的,则可以使用消息总线(例如ZeroMQ)作为消息处理器,警报发送器和数据库检查器之间的通信层。 The idea is to increase parallelism by having non-blocking communication occur through the bus and having each node on the bus do one thing only. 这个想法是通过总线进行非阻塞通信并使总线上的每个节点只做一件事来增加并行性。 You can then alter the ratio of node types depending on how long each stage of message processing takes. 然后,您可以根据每个消息处理阶段所需的时间来更改节点类型的比率。 (Ie to make the queue depth equal across the entire message processing process.) (即在整个消息处理过程中使队列深度相等。)

When you get a message, do two things: 收到消息后,请执行以下两项操作:

  • Check to see if it should trigger an alert (and send the alert if necessary, presumably) 检查是否应触发警报(并在必要时发送警报,大概是)
  • Insert it into the database 将其插入数据库

You don't need a message queue, multiple processes, IPC, or any of those things. 您不需要消息队列,多个进程,IPC或任何这些东西。 For example: 例如:

def messageReceived(self, message):
    self.checkForAlerts(message).addCallbacks(self.maybeAlert, log.err)
    self.saveMessageToDatabase(message).addErrback(log.err)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM