400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
400-800-0824
info@ymatrix.cn
YMatrix 文档
关于 YMatrix
标准集群部署
数据写入
数据迁移
数据查询
运维监控
参考指南
工具指南
数据类型
存储引擎
执行引擎
流计算引擎
灾难恢复
系统配置参数
索引
扩展
SQL 参考
常见问题(FAQ)
本课程教学视频请参考 YMatrix 数据接入
MatrixGate 简称 mxgate,是 YMatrix 自带的高性能数据加载工具。其位于 YMatrix 安装目录下的 bin/mxgate
,当前支持通过 SDK 或 HTTP 和 STDIN API 接口加载数据。数据格式支持 TEXT 和 CSV。
使用 mxgate 进行数据加载性能要远远高于原生 INSERT
语句。因为 mxgate 可以直接与 Segment 进行通信,不存在 Master 单点瓶颈。
mxgate 目前主要支持以下功能:
MatrixGate 加载数据的逻辑如下图所示:
INSERT 与 MatrixGate 对比:
写入方式 | 优势 | 劣势 | 适用场景 |
---|---|---|---|
直接 INSERT | 接口简单 | 吞吐性能低 | 吞吐性能低,几十万数据点/秒 |
MatrixGate | 吞吐性能高 准实时 |
需要额外部署,有运维成本 | 吞吐性能高,千万数据点/秒 |
经测试,MatrixGate 与 Influx 的数据导入性能对比接近 79:1。具体数据可参考时序数据库插入性能评测:YMatrix 是 InfluxDB 的 78 倍。
MatrixGate 提供如下运行模式:
下面演示如何使用这两种模式向数据表灌入数据,数据表 dest 的 Schema 如下:
=# CREATE TABLE dest(
time timestamp,
c1 int,
c2 text
)USING MARS3
DISTRIBUTED BY(c1)
ORDER BY(c1);
服务模式会有后台进程常驻,提供 HTTP 接口给用户,用来提交时序数据,是生产环境中普通使用的方式。
使用服务模式首先要生成配置文件,确定数据库连接信息、目标表等参数。
$ mxgate config --db-database test \
--db-master-host localhost \
--db-master-port 5432 \
--db-user mxadmin \
--target public.dest \
--time-format raw \
--delimiter ',' \
> mxgate.conf
如上命令中确定了如下信息:
参数名 | 描述 | 值 |
---|---|---|
--db-database | 数据库 | test |
--db-master-host | 数据库主机 | localhost |
--db-master-port | 数据库端口 | 5432 |
--db-user | 数据库用户名 | mxadmin |
--target | 目标表 | public.dest |
--time-format | 时间格式 | raw(明文) |
--delimiter | 分隔符 | , |
然后,启动 MatrixGate,在启动参数中指定刚才生成的配置文件:
$ mxgate start --config mxgate.conf
******************************************************
__ __ _ _ ____ _
| \/ | __ _| |_ _ __(_)_ __/ ___| __ _| |_ ___
| |\/| |/ _` | __| '__| \ \/ / | _ / _` | __/ _ \
| | | | (_| | |_| | | |> <| |_| | (_| | || __/
|_| |_|\__,_|\__|_| |_/_/\_\\____|\__,_|\__\___|
Version: v5.2.0
Your Copy is Licensed to: yMatrix.cn; 2023-10-25; any
******************************************************
Launching MatrixGate daemon...
MatrixGate daemon started successfully
启动成功后,下面使用 curl 工具发送 HTTP 请求提交数据。
注意!
在生产环境中则使用编程语言支持的 HTTP 库来提交数据。
创建测试数据文件 rows_header.csv
:
$ vi rows_header.csv
内容如下:
public.dest
2021-01-01 00:00:00,1,a1
2021-01-01 00:00:00,2,a2
2021-01-01 00:00:00,3,a3
在提交数据的时候,首行要指定目标表名,因为 MatrixGate 服务可能有多个目标表。
提交数据:
$ curl http://localhost:8086/ -X POST -H 'Content-Type: text/plain' --data-binary "@rows_header.csv"
MatrixGate 默认绑定 8086 端口,可以通过配置文件修改。
查询灌入的数据:
=# SELECT * FROM dest;
time | c1 | c2
---------------------+----+-----
2021-01-01 00:00:00 | 11 | a11
2021-01-01 00:00:00 | 12 | a12
2021-01-01 00:00:00 | 13 | a13
(3 rows)
更详细的 API 参数请参考文档。
MatrixGate 还提供了其他运维命令来进行运维管理。
查看状态
$ mxgate status
******************************************************
__ __ _ _ ____ _
| \/ | __ _| |_ _ __(_)_ __/ ___| __ _| |_ ___
| |\/| |/ _` | __| '__| \ \/ / | _ / _` | __/ _ \
| | | | (_| | |_| | | |> <| |_| | (_| | || __/
|_| |_|\__,_|\__|_| |_/_/\_\\____|\__,_|\__\___|
Version: v5.2.0
Your Copy is Licensed to: yMatrix.cn; 2023-10-25; any
******************************************************
PID 29429 alive
Launched At 2023-07-26 08:26:22
Up For 4 minutes 12 seconds
Binary /opt/ymatrix/matrixdb5/bin/mxgated
Log /home/mxadmin/gpAdminLogs/matrixgate.2023-07-26_082622-29429.log
Config /home/mxadmin/mxgate.conf
可以看到服务程序运行状态以及配置文件和日志路径,用来追查问题。
停止服务
$ mxgate stop
******************************************************
__ __ _ _ ____ _
| \/ | __ _| |_ _ __(_)_ __/ ___| __ _| |_ ___
| |\/| |/ _` | __| '__| \ \/ / | _ / _` | __/ _ \
| | | | (_| | |_| | | |> <| |_| | (_| | || __/
|_| |_|\__,_|\__|_| |_/_/\_\\____|\__,_|\__\___|
Version: v5.2.0
Your Copy is Licensed to: yMatrix.cn; 2023-10-25; any
******************************************************
PID 29429 stopped
观测服务
可以使用 mxgate watch
子命令来实时观测服务:
$ mxgate watch
******************************************************
__ __ _ _ ____ _
| \/ | __ _| |_ _ __(_)_ __/ ___| __ _| |_ ___
| |\/| |/ _` | __| '__| \ \/ / | _ / _` | __/ _ \
| | | | (_| | |_| | | |> <| |_| | (_| | || __/
|_| |_|\__,_|\__|_| |_/_/\_\\____|\__,_|\__\___|
Version:v5.2.0
Your Copy is Licensed to: yMatrix.cn; 2023-10-25; any
******************************************************
watch cmd will run forever until killed, you can use watch -T n to change the duration to n seconds;and you can use mxgate watch --info to get info of columns;
Time WCount ICount WSpeed/s ISpeed/s WBandWidth MB/S BlocakItems
2022-04-28 15:20:58 14478858 14527011 2598081 2627887 2395 0
2022-04-28 15:21:01 22231035 22633254 2584059 2702081 2222 0
2022-04-28 15:21:04 30494310 30500874 2754425 2622540 3551 0
2022-04-28 15:21:07 38004210 38032956 2503300 2510694 2862 0
2022-04-28 15:21:10 46188696 46298223 2728162 2755089 2227 0
...
或者使用 mxgate watch --history
来观测历史数据
$ mxgate watch --history
******************************************************
__ __ _ _ ____ _
| \/ | __ _| |_ _ __(_)_ __/ ___| __ _| |_ ___
| |\/| |/ _` | __| '__| \ \/ / | _ / _` | __/ _ \
| | | | (_| | |_| | | |> <| |_| | (_| | || __/
|_| |_|\__,_|\__|_| |_/_/\_\\____|\__,_|\__\___|
Version: v5.2.0
Your Copy is Licensed to: yMatrix.cn; 2023-10-25; any
******************************************************
TIME RANGE | SPEED/S | BANDWIDTH MB/S | BLOCK ITEMS
2023-07-28 16:00:00-2023-07-28 17:00:00 | 2208010 | 1254.48 | 0
2023-07-28 17:00:00-2023-07-28 18:00:00 | 1157920 | 1327.00 | 0
2023-07-28 18:00:00-2023-07-28 19:00:00 | 2228666 | 2162.32 | 0
2023-07-28 19:00:00-2023-07-28 20:00:00 | 1371092 | 2881.30 | 0
2023-07-28 20:00:00-2023-07-28 21:00:00 | 1575320 | 2608.20 | 0
命令行模式用来一次性灌入数据文件,结束后进程也随之退出。
还是刚才的数据文件,去掉第一行目标表,只保留数据行,执行如下命令:
$ cat rows.csv | mxgate --source stdin --db-database test --db-master-host localhost --db-master-port 5432 --db-user mxadmin --time-format raw --target public.dest --parallel 2 --delimiter ','
有关文件接入的更多方法请参考文件接入
mxgate 的迁移模式主要用来做单表高速数据迁移,支持将其他 Greenplum 5、Greenplum 6、YMatrix 集群的数据表迁移到当前 YMatrix 集群中,目前主要用法有如下三种:
注意!
迁移模式具体用法请见单表迁移工具 - mxgate,全库迁移方法请见全库迁移工具 - mxshift。
注意!
MatrixGate 工具完整介绍请见MatrixGate。