简体   繁体   English

无人机管理数据库设计

[英]Drone management database design

Overview概述

I'm currently building a prototype to track and control a fleet of drones.我目前正在构建一个原型来跟踪和控制一群无人机。

The prototype consists of a service and a web app.该原型由一个服务和一个 web 应用程序组成。 In the web app, the location of each drone is displayed in real-time on a map and the user can issue basic commands to each of these drones.在 web 应用程序中,每架无人机的位置实时显示在 map 上,用户可以向每架无人机发出基本命令。 The service is automated and can also issue commands to each of the drones at random times when certain conditions occur.该服务是自动化的,还可以在某些情况发生时随机向每架无人机发出命令。

I am using HiveMQ (an MQTT broker) to facilitate communication between drones, the web app and the service.我正在使用 HiveMQ(一个 MQTT 代理)来促进无人机、web 应用程序和服务之间的通信。 The web app and the service are both subscribed to the 'telemetry' topic to receive real-time data about the network of drones. web 应用程序和服务都订阅了“遥测”主题,以接收有关无人机网络的实时数据。 The broker will store the telemetry data for each drone directly into a database through the use of HiveMQ's extension functionality.代理将通过使用 HiveMQ 的扩展功能将每架无人机的遥测数据直接存储到数据库中。

Specific commands can only be executed if certain criteria are met.只有满足特定条件才能执行特定命令。

For example: To issue an 'execute mission' command to a drone the service or the web app will make a call to an API.例如:要向无人机发出“执行任务”命令,服务或 web 应用程序将调用 API。 The API will: API 将:

  1. Check the drone is not currently on a mission (drone status value must be idle)检查无人机当前未执行任务(无人机状态值必须为空闲)
  2. Check weather conditions are acceptable in the area the mission is to occur检查任务发生地区的天气状况是否可接受

(Note by 'mission' I mean a drone fly's to a series of set locations autonomously). (注意,“任务”是指无人机自动飞到一系列设定的位置)。

If conditions aren't met a response indicating this will be returned to the requester (web app or service).如果不满足条件,则会向请求者(Web 应用程序或服务)返回指示此情况的响应。 If conditions are met the API will issue the command to the appropriate drone via the MQTT broker and send a response to the requester.如果满足条件,API 将通过 MQTT 代理向相应的无人机发出命令,并向请求者发送响应。

Requirements要求

I need a storage mechanism that meets the following criteria:我需要一个满足以下条件的存储机制:

  1. I need to ensure that a race condition does not occur between the web app and the service.我需要确保 web 应用程序和服务之间不会发生争用情况。 That is if a request to issue a command to a drone is being made by the web app, a request made by the service in this time should be automatically rejected.也就是说,如果 web 应用程序正在发出向无人机发出命令的请求,则此时服务发出的请求应被自动拒绝。
  2. Drone status between the service and the web app are not synchronous, as a result, they need a synchronized point to check a drones status.服务和 web 应用程序之间的无人机状态不同步,因此,它们需要一个同步点来检查无人机状态。
  3. Drones will update their status every second, and API call's to issue commands will be made every 10 - 30 seconds.无人机将每秒更新一次状态,API 调用将每 10 - 30 秒发出一次命令。 There will be 5 drones in this prototype but I would like a solution that can scale to 50 drones.这个原型中将有 5 架无人机,但我想要一个可以扩展到 50 架无人机的解决方案。

Considered Solution考虑的解决方案

My solution would be that of a relational database - using a separate table with a 'request_lock' field, this field uses a row-level lock.我的解决方案是关系数据库的解决方案——使用带有“request_lock”字段的单独表,该字段使用行级锁。

When an API call is made it checks if this field is true, if true the request is rejected.当调用 API 时,它会检查此字段是否为真,如果为真则拒绝请求。 If it is false it sets the field to true performs the necessary condition checks and then sets the 'request_lock' field to false when once the command has reached the drone.如果为假,则将字段设置为真执行必要的条件检查,然后在命令到达无人机后将“request_lock”字段设置为假。

I am concerned the status update frequency from each drone does not fit a relational database model and won't scale well.我担心每架无人机的状态更新频率不适合关系数据库 model 并且无法很好地扩展。 Am I on the right track, or should I be looking to include a NoSQL database in some way to handle status updates?我是在正确的轨道上,还是应该以某种方式包含一个 NoSQL 数据库来处理状态更新?

Thank you to anyone who takes the time to answer.感谢任何花时间回答的人。

There are a lot of questions here, so I'll try to pick what seems to be most important:这里有很多问题,所以我将尝试选择似乎最重要的问题:

I am concerned the status update frequency from each drone does not fit a relational database model..我担心每架无人机的状态更新频率不适合关系数据库 model..

Should I use a relational or non-relational database?我应该使用关系数据库还是非关系数据库?

First, let's calculate the maximum number of drone status updates, per second.首先,让我们计算一下每秒无人机状态更新的最大次数。

Drones will update their status every second, and API call's [sic] to issue commands will be made every 10 - 30 seconds.无人机将每秒更新一次状态,API 调用的 [原文如此] 将每 10 - 30 秒发出一次命令。 There will be 5 drones in this prototype but I would like a solution that can scale to 50 drones.这个原型中将有 5 架无人机,但我想要一个可以扩展到 50 架无人机的解决方案。

  • 50 drones * 1 drone-update per second = 50 drone-updates per second 50 架无人机 * 每秒 1 次无人机更新 = 每秒 50 次无人机更新
  • 50 drones * (10 / 60) drone-commands per second = 8.3 drone-commands per second 50 架无人机 * (10 / 60) 每秒无人机指令 = 8.3 无人机指令每秒

So, can a relational database handle ~60 queries per second?那么,关系数据库每秒可以处理约 60 个查询吗?

Yes.是的。 Assuming reasonable query complexity, this is within the ability of a traditional relational database.假设查询复杂度合理,这在传统关系数据库的能力范围内。 I would not expect the database to need extraordinary system resources, either.我也不认为数据库需要非凡的系统资源。

If you'd like to confirm this level of performance with a benchmark, I'd recommend a tool like pgbench .如果您想通过基准测试来确认这种性能水平,我建议您使用pgbench之类的工具。

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

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