简体   繁体   English

最合适的节点服务器通信设计

[英]Most suitable node-server communication design

I struggle with designing a part of my project. 我在设计项目的一部分时遇到了困难。 The idea is that N nodes (each with one camera) would be continuously sending frames to a server for object detection and then the server would resend a response to each node with some information. 这个想法是,N个节点(每个节点带有一个摄像机)将不断向服务器发送帧以进行对象检测,然后服务器将向每个节点重新发送一些信息。

The goal is to handle each node possibly independently and to be able to receive next frame and process previous at the same time. 目标是可能独立处理每个节点,并能够接收下一帧并同时处理先前的帧。

As in Python, threads running in parallel are not in option, I'm considering a few approaches (assuming that I have a CPU that is capable of handling N * 2 threads in parallel: 像在Python中一样,不能选择并行运行线程,我正在考虑几种方法(假设我有一个能够并行处理N * 2个线程的CPU:

1) The server would spawn two processes (communicating with each other) for each node (one for receiving frames, and one for object detection). 1)服务器将为每个节点生成两个进程(相互通信)(一个用于接收帧,一个用于对象检测)。 (those processes would run independently from the main process) (那些进程将独立于主进程运行)

2) The server would be single-threaded and asynchronous. 2)服务器将是单线程且异步的。 Every received frame would be submitted to a process-pool for detection. 每个接收到的帧都将提交到进程池进行检测。

3) The server would spawn a thread for each node (one thread would handle receiving frames from one node). 3)服务器将为每个节点生成一个线程(一个线程将处理从一个节点接收帧)。 Every received frame would be submitted to a process-pool for object detection. 每个接收到的帧都将提交给进程池以进行对象检测。

4) The server would spawn a thread for each node and two separate threads within this thread, one for receiving and one for object detection 4)服务器将为每个节点生成一个线程,并在该线程中生成两个单独的线程,一个用于接收,一个用于对象检测

Which approach seems to have the most sense? 哪种方法似乎最有意义? Would you suggest something different? 您会提出一些不同的建议吗?

I love architectural kind of problems, Here what I would do if I have to do this project.: 我喜欢建筑方面的问题,如果必须执行此项目,我会怎么做。
Workflow: 工作流程:

  1. Node will send request to the server including frames and node ID 节点将向服务器发送请求,包括帧和节点ID
  2. Based on the node ID and the frames, Server will create a job in a queue using redis in memory storage to keep track of the jobs sent by the nodes and also store each request into a DB 根据节点ID和帧,服务器将使用内存中的Redis在队列中创建作业,以跟踪节点发送的作业,并将每个请求存储到数据库中
  3. Server will process each jobs by running a worker on the server which will fetch and process each jobs from redis queues. 服务器将通过在服务器上运行一个工作程序来处理每个作业,该工作程序将从redis队列中获取并处理每个作业。
  4. Update Job Record : Once done, the job will be marked as completed and result will be saved. 更新作业记录:完成后,该作业将被标记为已完成并保存结果。
  5. Node can make a call to the server to get status of each job posted by the node. 节点可以调用服务器以获取该节点发布的每个作业的状态。

You need to create REST API interface on the server to post the job from the node and save that request to the DB and create a job based on that request and also push it to the redis queue. 您需要在服务器上创建REST API接口,以从节点发布作业并将该请求保存到数据库,并基于该请求创建作业,并将其推送到Redis队列。 A worker will automatically pull out the jobs from the redis queues and update the DB record based on the processing result. 工作人员将自动从redis队列中取出作业,并根据处理结果更新数据库记录。

You need following on the server side : 您需要在服务器端执行以下操作:
- REST API -REST API
- Redis queue (RQ) Link -Redis队列(RQ) 链接
- DB server -数据库服务器

Using this architecture you can easily return light-weighted result immediately to the client and keep all the jobs under processing. 使用这种架构,您可以轻松地将轻量级的结果立即返回给客户端,并使所有作业都在处理中。 RESTful Architecture is widely used architecture but for time consuming jobs, we use queue processors and client will make request to us to check the status of any jobs posted to the server. RESTful体系结构是一种广泛使用的体系结构,但是对于耗时的工作,我们使用队列处理器,客户端将向我们发出请求,以检查发布到服务器的任何工作的状态。 If you need I can draw the architecture including much more detail. 如果需要,我可以绘制包含更多细节的体系结构。

In short: if you have client server architecture use REST APIs to communicate and post each request in an in-memory queue storage if the request posted by client is time consuming process and have multi-step jobs to do. 简而言之:如果客户端发布的请求是耗时的过程并且需要执行多步骤的工作,那么如果您具有客户端服务器体系结构,则可以使用REST API进行通信并将每个请求发布到内存队列存储中。 And using this architecture you can post any numbers of jobs as well as multiple workers, load balancers for the performance. 使用此体系结构,您可以发布任意数量的作业以及多个工作程序,负载平衡器以提高性能。

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

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