我们讲工业互联网、工业大数据,首先需要把数据从工业现场采集上来,这是第一步也是基础。
海量的数据从工业现场采集之后存在哪里呢?使用什么样的存储方式对后面的数据分析和计算有重要影响。
这里对数据库方式的存储进行了一个选型比较。
当前的数据库按类型分可以分为实时数据库,时序数据库,NoSQL数据库,关系型数据库。
实时数据库是工业领域长时间以来的数据存储方式,很多传统的工业软件厂商都提供实时数据库。今年来,随着物联网的发展,时序数据库的应用也越来越广。
1. 单条数据不会很长,但是数据量很大
2. 它们都带有时间戳,且按顺序生成
3. 数据大部分都是结构化的,用于描述某个参数在某个时间点的特征
4. 写入的频率会比查询的频率高很多
5. 已存储的数据很少有更新的需求
6. 用户会更关心一段时间的数据特征,而不是某一个时间点
7. 数据的查询分析大多基于某一个时间段或者某个数值范围
8. 需要进行统计和可视化的展示
这里分别选择从一个类型中选择一个代表进行选型比较。
时序数据库选择InfluxDB,这是当前排名最高的时序数据库;
NoSQL数据库选择MongoDB,这也是当前排名最高的非关系型数据库;
关系型数据库选择PostgreSQL。为什么没有选mysql,主要还是从开放性考虑,在功能和性能上PostgreSQL和mysql都非常好,基本差别不大,但是Mysql属于Oracle之后,能否一致保持开源特性让人担忧,PostgreSQL则完全没有这方面的担心。
图一是截止2020.10的数据库的最新排名。
图1:数据库排名(截止2020.10) https://db-engines.com/en/ranking
表1:数据库分项比较
Name
InfluxDB
MongoDB
PostgreSQL
Description
DBMS for storing time series, events and metrics
One of the most popular document stores available both as a fully managed cloud service and for deployment on self-managed infrastructure
Widely used open source RDBMS
Primary database model
Time Series DBMS
Document store
Relational DBMS
Secondary database models
Search engine
Document store
DB-Engines Ranking
Score:24.15
Rank:
#28 Overall
#1 Time Series DBMS
Score:448.02
Rank:
#5 Overall
#1 Document stores
Score:542.40
Rank:
#4 Overall
#4 Relational DBMS
Trend Chart
License
MIT-License; commercial enterprise version available
MongoDB Inc.'s Server Side Public License v1. Prior versions were published under GNU AGPL v3.0. Commercial licenses are also available.
BSD
Implementation language
Go
C++
C
Server operating systems
Linux
OS X
Linux
OS X
Solaris
Windows
FreeBSD
HP-UX
Linux
NetBSD
OpenBSD
OS X
Solaris
Unix
Windows
Data scheme
schema-free
schema-free
yes
Typing
Numeric data and Strings
yes
yes
XML support
no
yes
Secondary indexes
no
yes
yes
SQL
SQL-like query language
Read-only SQL queries via the MongoDB Connector for BI
yes
APIs and other access methods
HTTP API
JSON over UDP
proprietary protocol using JSON
ADO.NET
JDBC
native C library
ODBC
streaming API for large objects
Supported programming languages
.Net
Clojure
Erlang
Go
Haskell
Java
JavaScript
JavaScript (Node.js)
Lisp
Perl
PHP
Python
R
Ruby
Rust
Scala
(don’t support C++)
Actionscript info
C
C#
C++
Clojure info
ColdFusion info
D info
Dart info
Delphi info
Erlang
Go
Groovy info
Haskell
Java
JavaScript
Lisp info
Lua info
MatLab info
Perl
PHP
PowerShell info
Prolog info
Python
R info
Ruby
Rust
Scala
Smalltalk info
Swift
.Net
C
C++
Delphi
Java info
JavaScript (Node.js)
Perl
PHP
Python
Tcl
Triggers
no
yes(in MongoDB Atlas only)
yes
Partitioning methods
Sharding
(enterprise version only)
Sharding
partitioning by range, list and (since PostgreSQL 11) by hash
Replication methods
selectable replication factor
(enterprise version only)
Multi-Source deployments with MongoDB Atlas Global Clusters
Source-replica replication
Source-replica replication
MapReduce
no
yes
no
Consistency concepts
Eventual Consistency
Immediate Consistency
Immediate Consistency
Foreign keys
no
no
yes
Transaction concepts
no
Multi-document ACID Transactions with snapshot isolation
ACID
Concurrency
yes
yes
yes
Durability
yes
yes
yes
In-memory capabilities
yes
(Depending on used storage engine)
yes
no
Access control
simple rights management via user accounts
Access rights for users and roles
fine grained access rights according to SQL-standard
数据库
优势
劣势
InfluxDB
时序数据库
schema-free
官方不提供C++ API,需要自己封装;(https://github.com/awegrzyn/influxdb-cxx)
单机版,不支持集群
MongoDB
schema-free,
提供C++ API
支持集群
没有时序,需要自己实现
PostgreSQL
提供C++ API
支持集群
has schema,table can not change.
没有时序,需要自己实现
(https://github.com/timescale/timescaledb)
只针对开源版本来说,Influxdb不支持集群,集群和高可靠用需要自己设计实现方案,在生产环境下不是最佳选择,如果不考虑这个方面或者可以购买企业版的话,influxdb是不错的选择。
PostgreSQL 在有了timescaledb 之后具备了时序数据库的功能,同时又天然支持集群和高可用方案,很好的选择。
MongoDB需要自己设计时序方案,稍显麻烦了,如果技术实力可以的话,也是一个选择。
