IoTDB + Grafana 实现数据可视化(3)
前言
之前简单使用了IoTDB进行可视的操作步骤,这次进行IoTDB性能方面的测试。
一、简述
采用自动生成数据的方式,写入不同组的数据,在相同的环境下对IoTDB的吞吐量进行时间测试,并记录数据。之后使用相同的数据写入方式,对现存的数据库进行测试,最后进行比较,以此得到不同时序数据的吞吐能力。
·本次实验采用相同性能的虚拟机进行测试。
二、使用步骤
1.配置虚拟机
虚拟机配置如下
实验环境 | 配置描述 |
---|---|
操作系统 | CentOS-7-x86_64-Minimal-2009 |
CPU | 2.40 GHz * 1 |
内存 | 1 GB |
SCSI | 20 GB |
Apache IoTDB version | 0.11.2 |
Maven version | 3.6.3 |
JDK version | 1.8 |
Grafana version | 1.8 |
Grafana | 7.5.2 |
2.创建测试数据
为了深入挖掘ioTDB的压力测试的性能,采用不同数据类型的数据,基本包括了常用的数据类型。采用random方法随机生成数据,每组数据包括10条Int型数据,10条float型数据,10条double型数据,10条boolean型数据,之后分别上传100组,1000组,3000组,5000组,10000组,100000组,得到数据的插入时间。
3.创建存储组
代码如下:
for (int i = 1; i < 11; i++) {
statement.execute("CREATE TIMESERIES root.testspeed.I"+i+" WITH DATATYPE=INT32,ENCODING=RLE;");
statement.execute("CREATE TIMESERIES root.testspeed.d"+i+" WITH DATATYPE=double,ENCODING=RLE;");
statement.execute("CREATE TIMESERIES root.testspeed.f"+i+" WITH DATATYPE=float ,ENCODING=RLE;");
statement.execute("CREATE TIMESERIES root.testspeed.b"+i+" WITH DATATYPE=BOOLEAN,ENCODING=RLE;"); }
4.生成随机数据
static DataEntity AutoGetDAta(){
DataEntity dataEntity = new DataEntity();
Random random = new Random();
dataEntity.setId(random.nextInt(1024));
//dataEntity.setDatetime(datetime);
dataEntity.setInitialSulfurContent(random.nextDouble()+120);
dataEntity.setInitialOctaneNumber(random.nextDouble()+88);
dataEntity.setSulfurContentOfTheProduct(random.nextDouble()+88);
dataEntity.setProductOctaneNumber(random.nextDouble()+3);
dataEntity.setLossOfOctaneNumber(random.nextDouble()+1);
dataEntity.setV1(random.nextDouble()+160);
dataEntity.setV2(random.nextDouble());
dataEntity.setV3(random.nextDouble()+2);
dataEntity.setV4(random.nextDouble());
dataEntity.setV5(random.nextDouble()+60);
dataEntity.setV6(random.nextDouble()+410);
dataEntity.setV7(random.nextDouble()+70);
dataEntity.setV8(random.nextDouble());
dataEntity.setV9(random.nextDouble()+28);
dataEntity.setV10(random.nextDouble()+83);
dataEntity.setV11(random.nextDouble()+ random.nextInt(300)+600);
dataEntity.setV12(random.nextDouble()+230);
dataEntity.setV13(random.nextDouble()+200);
dataEntity.setV14(random.nextInt()+520222);
dataEntity.setV16(random.nextDouble()+50);
return dataEntity;
}
5.写入数据
Timestamp nowdate = new Timestamp(date.getTime());
// String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(nowdate);
DataEntity dataEntity1 = AutomaticallyGenerateData.AutoGetDAta();
System.out.println(dataEntity1.toString());
/*
假设只有一个存储组 1 Storage Group
有三台设备 Device1 Device2 Device3
Device1 包含了 initialSulfurContent,InitialOctaneNumber 初始值
Device2 SulfurContentOfTheProduct,ProductOctaneNumber,LossOfOctaneNumber 结果值
Device3 v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16 几个设备的值
*/
//d1
//Drvice1.initialSulfurContent
statement.addBatch("insert into root.Drvice1(timestamp,initialSulfurContent) values("+time+","+dataEntity1.getInitialSulfurContent()+");");
// Drvice1.InitialOctaneNumber
statement.addBatch("insert into root.Drvice1(timestamp,InitialOctaneNumber) values("+time+","+dataEntity1.getInitialOctaneNumber()+");");
//d2
// LossOfOctaneNumber
statement.addBatch("insert into root.Drvice2(timestamp,LossOfOctaneNumber) values("+time+","+dataEntity1.getLossOfOctaneNumber()+");");
// ProductOctaneNumber
statement.addBatch("insert into root.Drvice2(timestamp,ProductOctaneNumber) values("+time+","+dataEntity1.getProductOctaneNumber()+");");
// SulfurContentOfTheProduct
statement.addBatch("insert into root.Drvice2(timestamp,SulfurContentOfTheProduct) values("+time+","+dataEntity1.getSulfurContentOfTheProduct()+");");
//d3
statement.addBatch("insert into root.Drvice3(timestamp,V1) values("+time+","+dataEntity1.getV1()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V2) values("+time+","+dataEntity1.getV2()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V3) values("+time+","+dataEntity1.getV3()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V4) values("+time+","+dataEntity1.getV4()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V5) values("+time+","+dataEntity1.getV5()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V6) values("+time+","+dataEntity1.getV6()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V7) values("+time+","+dataEntity1.getV7()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V8) values("+time+","+dataEntity1.getV8()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V9) values("+time+","+dataEntity1.getV9()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V10) values("+time+","+dataEntity1.getV10()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V11) values("+time+","+dataEntity1.getV11()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V12) values("+time+","+dataEntity1.getV12()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V13) values("+time+","+dataEntity1.getV13()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V14) values("+time+","+dataEntity1.getV14()+");");
statement.addBatch("insert into root.Drvice3(timestamp,V16) values("+time+","+dataEntity1.getV16()+");");
statement.executeBatch();
// statement.executeQuery("select * from root.Drvice3");
outputResult(statement.getResultSet());
statement.clearBatch();
6.得到结果
组数 | 时间 |
---|---|
100组 | 2.067s |
1000组 | 16.939s |
3000组 | 49.922s |
5000组 | 79.58s |
10000组 | 163.158s |
7.实验感想
本次实验采用JDBC操作IoTDB,对其进行了压测,使用了最原始的虚拟机以及最基本的数据写入方法,之后的实验,将会以同样的写入方式对Mysql、InfluxDB、TimescaleDB等使用较多的数据库进行单机版测试,以及尝试配置集群测试。