简介:大家好,我是向阳逐梦,座右铭是向着太阳,追逐梦想。很快乐自己能够参与这次由TDengine举行的征文活动,把自己与TDengine在2022 年产生的故事用文字告知大家。

2022年行将走过,TDengine在这一年的前进信任大家都是众所周知的,不只GitHub突破了20000粉丝,并且还遭到国内外开发者更广泛的重视。更是推出了产品的3.0版别,叠加了云原生、流核算等立异元素,处理了时序数据库业界难解的高基数难题,还对查询引擎、存储引擎进行了进一步的优化与晋级…… **

接下来就与大家一同共享一下我与TDengine之间的经历和故事吧,希望与大家一同共勉!

一、什么是TDengine

开源、高性能、云原生

极简的时序数据处理渠道

1、TDengine的介绍

TDengine是一款开源、云原生的时序数据库(Time Series Database),专为物联网、工业互联网、金融、IT 运维监控等场景规划并优化,具有极强的弹性弹性才能。一起它还带有内建的缓存、流式核算、数据订阅等体系功用,能大幅减少体系规划的复杂度,下降研制和运营本钱,是一个极简的时序数据处理渠道。它能让大量设备、数据采集器每天产生的高达TB甚至PB级的数据得到高效实时的处理,对业务的运转状况进行实时的监测、预警,从大数据中挖掘出商业价值。

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

2、TDengine 3.0的介绍

TDengine 3.0带来了几大中心特性,包含云原生架构、流式核算,还增强了数据订阅功用;更重要的是,3.0系列版别开始供给了全渠道支撑,服务器/客户端均已支撑 Linux、Windows 和 MacOS

TDengine 3.0是一款真正的云原生时序数据库(Time Series Database,TSDB)。它有几大亮点:

  • 能够支撑 10 亿个设备、100 个节点
  • 支撑存储与核算别离,引进了核算节点(QNode),并重构了整个核算引擎
  • 完善并优化了对音讯行列、流式核算和缓存的支撑,引进事件驱动的流式核算
  • 处理了困扰时序数据库的高基数问题

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

二、TDengine的下载与装置

1、翻开TDengine的官方下载链接。

官方下载链接:TDengine

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

2、依据自己的操作体系下载即可,我这里是Windows体系。

留意:现在 TDengine 在 Windows 渠道上只支撑 Windows Server 2016/2019 和 Windows 10/11。

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验
然后点击当即下载,进入新的界面后选择V3.0版别,Windows体系。

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验
分别下载下面的服务器装置包和客户端装置包,便利后边进行运用。下载之后的程序为exe可执行程序,能够直接双击进行装置。(留意:下载需要输入自己的邮箱获取下载的链接

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

三、关于TDengine的介绍与运用

TDengine完好的软件包包含服务端(taosd)、应用驱动(taosc)、用于与第三方体系对接并供给 RESTful 接口的 taosAdapter、命令行程序(CLI,taos)和一些东西软件。现在 taosdump、TDinsight 仅在 Linux 体系上装置和运转,后续将支撑 Windows、macOS 等体系。TDengine 除了供给多种言语的衔接器之外,还经过taosAdapter供给RESTful接口。

为便利运用,规范的服务端装置包包含了 taosd、taosAdapter、taosc、taos、taosdump、taosBenchmark、TDinsight 装置脚本和示例代码;如果您只需要用到服务端程序和客户端衔接的 C/C++ 言语支撑,也能够仅下载 Lite 版别的装置包。

1、TDengine软件应用指南

应用指南:TDengine软件

2、主要功用

TDengine的主要功用如下:

(1)支撑写入数据

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

(2)支撑查询数据

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

(3)支撑缓存与流式核算

(4)支撑数据订阅、可视化、集群、管理等等

3、竞赛优势

TDengine充分利用了时序数据特色,比方结构化、无需事务、很少删去或更新、写多读少等等,因而与其他时序数据库相比。

TDengine具有以下特色:

  • [高性能]:TDengine是唯一一个处理了时序数据存储的高基数难题的时序数据库,支撑上亿数据采集点,并在数据插入、查询和数据压缩上远胜其它时序数据库。
  • [极简时序数据渠道]:TDengine内建缓存、流式核算和数据订阅等功用,为时序数据的处理供给了极简的处理方案,然后大幅下降了业务体系的规划复杂度和运维本钱。
  • [云原生]:经过原生的分布式规划、数据分片和分区、存算别离、RAFT协议、Kubernetes布置和完好的可观测性,TDengine是一款云原生时序数据库并且能够布置在公有云、私有云和混合云上。
  • [简单易用]:对体系管理员来说,TDengine大幅下降了管理和保护的代价。对开发者来说, TDengine供给了简单的接口、极简的处理方案和与第三方东西的无缝集成。对数据分析专家来说,TDengine供给了快捷的数据拜访才能。
  • [分析才能]:经过超级表、存储核算别离、分区分片、预核算和其它技能,TDengine能够高效地阅读、格式化和拜访数据。
  • [中心开源]:TDengine的中心代码包含集群功用悉数在开源协议下公开。全球超过140k个运转实例,GitHub Star 20k,且拥有一个活泼的开发者社区。

4、技能生态

在整个时序大数据渠道中,TDengine扮演的角色如下:

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验
上图中,左边是各种数据采集或音讯行列,包含 OPC-UA、MQTT、Telegraf、也包含 Kafka,他们的数据将被源源不断的写入到 TDengine。右侧则是可视化、BI 东西、组态软件、应用程序。下侧则是TDengine自身供给的命令行程序(CLI)以及可视化管理东西。

下图为智能电表数据模型示意图

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

5、关于学习TDengine的常识地图

TDengine常识地图中涵盖了TDengine的各种常识点,揭示了各概念实体之间的调用联系和数据流向。学习和了解TDengine常识地图有助于你快速掌握TDengine的常识体系。

TDengine常识地图

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

四、TDengine 3.0的基础操作

关于TDengine 3.0的运用还有许多留意的地方,不能像之间的2.X相同操作。 关于TDengine 3.0的运用感触颇多,详情请见TDengine 3.0踩坑实录 接下来介绍一下TDengine 3.0的基础操作,详细资料请检查官方文档

最近在学习Linux体系,在这里我以Linux体系来进行演示:

1、装置

装置包下载地址:装置包

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验

(1)装备地址解析

vi /etc/hosts
192.168.0.14    c0-14
192.168.0.15    c0-15
192.168.0.16    c0-16

(2)创立相关目录

mkdir -p /taos/{data,log,tmp,core,soft}

(3)装置 TDengine Server

cd /taos/soft/
tar xzf TDengine-server-3.0.0.1-Linux-x64.tar.gz
cd TDengine-server-3.0.0.1
./install.sh -e no

2、创立集群

CREATE DNODE "fqdn:port";
[root@c0-14 taos]# taos
Welcome to the TDengine Command Line Interface, Client Version:3.0.0.1
Copyright (c) 2022 by TDengine, all rights reserved.
Server is Community Edition.
taos> show dnodes;
     id      |            endpoint            | vnodes | support_vnodes |   status   |       create_time       |              note              |
=================================================================================================================================================
           1 | c0-14:6030                     |      0 |              4 | ready      | 2022-08-24 11:26:31.343 |                                |
Query OK, 1 rows in database (0.001536s)
taos> create dnode "c0-15:6030";
Query OK, 0 of 0 rows affected (0.000694s)
taos> create dnode "c0-16:6030";
Query OK, 0 of 0 rows affected (0.000651s)
taos> show dnodes;
     id      |            endpoint            | vnodes | support_vnodes |   status   |       create_time       |              note              |
=================================================================================================================================================
           1 | c0-14:6030                     |      0 |              4 | ready      | 2022-08-24 11:26:31.343 |                                |
           2 | c0-15:6030                     |      0 |              4 | ready      | 2022-08-24 11:26:55.594 |                                |
           3 | c0-16:6030                     |      0 |              4 | ready      | 2022-08-24 11:26:59.504 |                                |
Query OK, 3 rows in database (0.001595s)

show dnodes的输出里边多了个support_vnodes列,这个列说明晰对应节点答应创立的 vnode 个数。

3、创立数据库

Query OK, 0 of 0 rows affected (8.369874s)
taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
 test                           |
Query OK, 3 rows in database (0.001277s)

和2.x最大的差异就是多了information_schema和performance_schema两张表。 TDengine 3.0的建库语句也产生了很大变化,经过show create database 可要看到建库的参数越来越陌生了。

taos> show create database test\G;
*************************** 1.row ***************************
       Database: test
Create Database: CREATE DATABASE `test` BUFFER 96 CACHEMODEL 'none' COMP 2 DURATION 14400m WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 KEEP 5256000m,5256000m,5256000m PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 3 STRICT 'off' WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0
Query OK, 1 rows in database (0.000644s)

4、写入/查询数据

还好,仍是本来的味道。

taos> insert into t1 values(now,1);
Query OK, 1 of 1 rows affected (0.001821s)
taos> insert into t1 values(now,2);
Query OK, 1 of 1 rows affected (0.001061s)
taos> insert into t1 values(now,3);
Query OK, 1 of 1 rows affected (0.001234s)
taos> select * from t1;
           ts            |     v1      |
========================================
 2022-08-24 11:31:56.354 |           1 |
 2022-08-24 11:31:58.600 |           2 |
 2022-08-24 11:32:00.849 |           3 |
Query OK, 3 rows in database (0.001667s)
taos> select * from stb;
           ts            |     v1      |     t1      |               t2               |
=======================================================================================
 2022-08-24 11:31:56.354 |           1 |           1 | tag1                           |
 2022-08-24 11:31:58.600 |           2 |           1 | tag1                           |
 2022-08-24 11:32:00.849 |           3 |           1 | tag1                           |
Query OK, 3 rows in database (0.002319s)

5、taosBenchmark

[root@c0-14 taos]# taosBenchmark -y
[08/24 11:33:01.896648] INFO: taos client version: 3.0.0.1
[08/24 11:33:02.939009] INFO: create database: <CREATE DATABASE IF NOT EXISTS test precision 'ms';>
[08/24 11:33:04.941904] INFO: stable meters does not exist, will create one
[08/24 11:33:04.942265] INFO: create stable: <CREATE TABLE IF NOT EXISTS test.meters (ts TIMESTAMP,current float,voltage int,phase float) TAGS (groupid int,location binary(16))>
[08/24 11:33:04.944294] INFO: generate stable<meters> columns data with lenOfCols<80> * prepared_rand<10000>
[08/24 11:33:04.953617] INFO: generate stable<meters> tags data with lenOfTags<54> * childTblCount<10000>
[08/24 11:33:04.956969] INFO: start creating 10000 table(s) with 8 thread(s)
[08/24 11:33:04.959901] INFO: thread[0] start creating table from 0 to 1249
[08/24 11:33:04.960719] INFO: thread[1] start creating table from 1250 to 2499
[08/24 11:33:04.961634] INFO: thread[2] start creating table from 2500 to 3749
[08/24 11:33:04.962011] INFO: thread[3] start creating table from 3750 to 4999
[08/24 11:33:04.962637] INFO: thread[4] start creating table from 5000 to 6249
[08/24 11:33:04.963563] INFO: thread[5] start creating table from 6250 to 7499
[08/24 11:33:04.964074] INFO: thread[6] start creating table from 7500 to 8749
[08/24 11:33:04.966660] INFO: thread[7] start creating table from 8750 to 9999
[08/24 11:33:06.038676] INFO: Spent 1.0820 seconds to create 10000 table(s) with 8 thread(s), already exist 0 table(s), actual 10000 table(s) pre created, 0 table(s) will be auto created
[08/24 11:33:06.038705] INFO: record per request (30000) is larger than insert rows (10000) in progressive mode, which will be set to 10000
[08/24 11:33:06.051761] INFO: Estimate memory usage: 11.74MB
................
[08/24 11:37:14.542688] INFO: thread[3] completed total inserted rows: 12500000, 50808.82 records/second
[08/24 11:37:16.653293] INFO: thread[4] completed total inserted rows: 12500000, 50377.97 records/second
[08/24 11:37:17.576138] INFO: thread[1] completed total inserted rows: 12500000, 50185.57 records/second
[08/24 11:37:17.926826] INFO: thread[5] completed total inserted rows: 12500000, 50120.61 records/second
[08/24 11:37:18.003390] INFO: thread[6] completed total inserted rows: 12500000, 50100.36 records/second
[08/24 11:37:18.115691] INFO: thread[2] completed total inserted rows: 12500000, 50078.72 records/second
[08/24 11:37:18.904192] INFO: thread[0] completed total inserted rows: 12500000, 49922.57 records/second
[08/24 11:37:19.122251] INFO: thread[7] completed total inserted rows: 12500000, 49878.25 records/second
[08/24 11:37:19.124718] INFO: Spent 253.069134 seconds to insert rows: 100000000 with 8 thread(s) into test 395148.94 records/second
[08/24 11:37:19.124737] INFO: insert delay, min: 17.99ms, avg: 199.27ms, p90: 526.29ms, p95: 640.49ms, p99: 3429.31ms, max: 7109.14ms
taos> select count(*) from test.meters;
       count(*)        |
========================
             100000000 |
Query OK, 1 rows in database (0.415701s)
taos> use test;
Database changed.
taos> show stables;
          stable_name           |
=================================
 meters                         |
Query OK, 1 rows in database (0.001924s)

想检查超级表下有多少子表,show stables 已经不能担任了。
TDengine 3.0只能用以下两种方法:

taos> select count(*) from information_schema.ins_tables where stable_name='meters' and db_name='test';
       count(*)        |
========================
                 10000 |
Query OK, 1 rows in database (0.027683s)
taos> select count(*) from (select distinct tbname from meters);
       count(*)        |
========================
                 10000 |
Query OK, 1 rows in database (0.019055s)

6、数据备份康复

TDengine 3.0 的备份康复东西仍是taosdump
试用了一遍,效率仍是那么安逸。

7、康复数据

[root@c0-14 taos]# taosdump -i /taos/dump
==============================
========== arguments config =========
taosdump version 2.1.2
host: (null)
user: root
port: 0
outpath: 
inpath: /taos/dump
resultFile: ./dump_result.txt
all_databases: false
databases: false
databasesSeq: (null)
schemaonly: false
with_property: true
answer_yes: false
avro codec: snappy
data_batch: 16383
thread_num: 8
allow_sys: false
escape_char: true
loose_mode: false
isDumpIn: true
arg_list_len: 0
[0]: Restoring from test.3322624946919.1.avro-tbtags ...
............
[6]:100%
OK: [1] 10000 row(s) of file(test.3322625031319.6565.avro) be successfully dumped in!
.OK: [2] 10000 row(s) of file(test.3322625048330.7970.avro) be successfully dumped in!
.OK: [3] 10000 row(s) of file(test.3322625065322.623.avro) be successfully dumped in!
.OK: [1] 10000 row(s) of file(test.3322625031327.5310.avro) be successfully dumped in!
.OK: [2] 10000 row(s) of file(test.3322625048322.4216.avro) be successfully dumped in!
.OK: [3] 10000 row(s) of file(test.3322625065338.1873.avro) be successfully dumped in!
[3]:100%
OK: [1] 10000 row(s) of file(test.3322625031335.9059.avro) be successfully dumped in!
[1]:100%
OK: [2] 10000 row(s) of file(test.3322625048335.464.avro) be successfully dumped in!
.OK: [2] 10000 row(s) of file(test.3322625048339.9216.avro) be successfully dumped in!
[2]:100%
OK: 100000000 row(s) dumped in!

8、校验数据

taos> select count(*) from meters;
       count(*)        |
========================
             100000000 |
Query OK, 1 rows in database (19.131576s)
taos> select count(*) from (select distinct tbname from meters);
       count(*)        |
========================
                 10000 |
Query OK, 1 rows in database (0.173748s)

五、关于TDengine 3.0的GitHub拜访

在GitHub社区有许多的功用,用户能够在上面进行提问,将会有来自国内外的客户进行技能的沟通与答疑,非常的便利。

GitHub社区的拜访地址

TDengine 3.0 & 时序数据库(Time Series Database)的学习与使用经验
总归,关于TDengine 3.0的晋级,功用方面变得愈加强壮,关于之前的2.X来说,有许多地方是兼容的,可是也产生了必定的改变。可是运用起来愈加高效,让平时的工作和数据处理效率也变得更高。