inlfuxdb版本_InfluxDB和MySQL的读写对比测试
今天进行了InfluxDB和MySQL的读写对比测试,这里记录下结果,也方便我以后查阅。
操作系统: CentOS6.5_x64
InfluxDB版本 : v1.1.0
MySQL版本:v5.1.73
CPU : Intel(R) Core(TM) i5-2320 CPU @ 3.00GHz
内存 :12G
硬盘 :SSD
一、MySQL读写测试
测试准备
初始化SQL语句:
CREATE DATABASEtestMysql;CREATE TABLE`monitorStatus` (
`system_name`VARCHAR(20) NOT NULL,
`site_name`VARCHAR(50) NOT NULL,
`equipment_name`VARCHAR(50) NOT NULL,
`current_value`DOUBLE NOT NULL,
`timestamp` BIGINT(20) NULL DEFAULT NULL,INDEX`system_name` (`system_name`),INDEX`site_name` (`site_name`),INDEX`equipment_name` (`equipment_name`),INDEX `timestamp` (`timestamp`)
)
ENGINE=InnoDB;
单写测试代码(insertTest1.c):
#include #include#include#include"mysql/mysql.h"
#define N 100
intmain() { MYSQL*conn_ptr;intres;intt,i,j;
int64_t tstamp= 1486872962;
srand(time(NULL));
t=0;
conn_ptr=mysql_init(NULL);if (!conn_ptr)
{
printf("mysql_init failed\n");returnEXIT_FAILURE;
}
conn_ptr= mysql_real_connect(conn_ptr,"localhost","root","","testMysql",0,NULL,0);if(conn_ptr)
{for(i=1;i<= 10000;i++)
{
mysql_query(conn_ptr,"begin");for(j=0;j
{char query[1024]={0};
sprintf(query,"insert into monitorStatus values ('sys_%d','s_%d','e_%d','0.%02d','%lld');",//j%10,(t+i)%10,(t+j)%10,(t+i+j)%100,tstamp);
j%10,(t+i)%10,(t+j)%10,rand()%100,tstamp);//printf("query : %s\n",query);
res =mysql_query(conn_ptr,query);if (!res)
{//printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(conn_ptr));
}else{
fprintf(stderr,"Insert error %d: %sn",mysql_errno(conn_ptr),mysql_error(conn_ptr));
}if(j%10 == 0) tstamp+=1;
}
mysql_query(conn_ptr,"commit");//printf("i=%d\n",i);
}
}else{
printf("Connection failed\n");
}
mysql_close(conn_ptr);returnEXIT_SUCCESS;
}
View Code
可根据情况调整测试代码中的N参数。
单读测试代码(queryTest1.c):
#include #include#include"mysql/mysql.h"
intmain()
{
MYSQL*conn_ptr;
MYSQL_RES*res_ptr;
MYSQL_ROW sqlrow;
MYSQL_FIELD*fd;intres, i, j;
conn_ptr=mysql_init(NULL);if (!conn_ptr)
{returnEXIT_FAILURE;
}
conn_ptr= mysql_real_connect(conn_ptr,"localhost","root","","testMysql", 0, NULL, 0);if(conn_ptr)
{
res= mysql_query(conn_ptr,"select * from `monitorStatus` where system_name='sys_8' and site_name='s_9' and equipment_name='e_6' order by timestamp desc limit 10000;");if(res)
{
printf("SELECT error:%s\n",mysql_error(conn_ptr));
}else{
res_ptr=mysql_store_result(conn_ptr);if(res_ptr)
{
printf("%lu Rows\n",(unsigned long)mysql_num_rows(res_ptr));
j=mysql_num_fields(res_ptr);while((sqlrow =mysql_fetch_row(res_ptr)))
{continue;for(i = 0; i < j; i++)
printf("%s\t", sqlrow[i]);
printf("\n");
}if(mysql_errno(conn_ptr))
{
fprintf(stderr,"Retrive error:s\n",mysql_error(conn_ptr));
}
}
mysql_free_result(res_ptr);
}
}else{
printf("Connection failed\n");
}
mysql_close(conn_ptr);returnEXIT_SUCCESS;
}
View Code
Makefile文件:
all:gcc -g insertTest1.c -o insertTest1 -L/usr/lib64/mysql/ -lmysqlclientgcc -g queryTest1.c -o queryTest1 -L/usr/lib64/mysql/ -lmysqlclient
clean:rm -rf insertTest1rm -rf queryTest1
测试数据记录
磁盘空间占用查询:
使用du方式(新数据库,仅为测试):
du -sh /var/lib/mysql
查询特定表:
useinformation_schema;select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from TABLES where table_schema='testMysql' and table_name='monitorStatus';
测试结果:
100万条数据
[root@localhost mysqlTest]# time ./insertTest1
real 1m20.645s
user 0m8.238s
sys 0m5.931s
[root@localhost mysqlTest]#time ./queryTest110000Rows
real 0m0.269s
user 0m0.006s
sys 0m0.002s
原始数据 : 28.6M
du方式 : 279MB
sql查询方式: 57.59MB
写入速度: 12398 / s
读取速度: 37174 / s
1000万条数据
root@localhost mysqlTest]# time ./insertTest1
real 7m15.003s
user 0m48.187s
sys 0m33.885s
[root@localhost mysqlTest]#time ./queryTest110000Rows
real 0m6.592s
user 0m0.005s
sys 0m0.002s
原始数据 : 286M
du方式 : 2.4G
sql查询方式: 572MB
写入速度: 22988 / s
读取速度: 1516 / s
3000万条数据
[root@localhost mysqlTest]# time ./insertTest1
real 20m38.235s
user 2m21.459s
sys 1m40.329s
[root@localhost mysqlTest]#time ./queryTest110000Rows
real 0m4.421s
user 0m0.004s
sys 0m0.004s
原始数据 : 858M
du方式 : 7.1G
sql查询方式: 1714MB
写入速度: 24228 / s
读取速度: 2261 / s
二、InfluxDB读写测试
测试准备
需要将InfluxDB的源码放入 go/src/github.com/influxdata 目录
单写测试代码(write1.go):
package main
import ("log"
"time"
"fmt"
"math/rand"
"github.com/influxdata/influxdb/client/v2")const(
MyDB= "testInfluxdb"username= "root"password= "") func queryDB(clnt client.Client, cmdstring) (res []client.Result, err error) {
q :=client.Query{
Command: cmd,
Database: MyDB,
}if response, err := clnt.Query(q); err ==nil {if response.Error() !=nil {returnres, response.Error()
}
res=response.Results
}else{returnres, err
}returnres, nil
}
func writePoints(clnt client.Client,numint) {
sampleSize := 1 * 10000rand.Seed(42)
t :=num
bp, _ :=client.NewBatchPoints(client.BatchPointsConfig{
Database: MyDB,
Precision:"us",
})for i := 0; i < sampleSize; i++{
t+= 1tags := map[string]string{"system_name": fmt.Sprintf("sys_%d",i%10),"site_name":fmt.Sprintf("s_%d", (t+i) % 10),"equipment_name":fmt.Sprintf("e_%d",t % 10),
}
fields := map[string]interface{}{"value" : fmt.Sprintf("%d",rand.Int()),
}
pt, err := client.NewPoint("monitorStatus", tags, fields,time.Now())if err !=nil {
log.Fatalln("Error:", err)
}
bp.AddPoint(pt)
}
err :=clnt.Write(bp)if err !=nil {
log.Fatal(err)
}//fmt.Printf("%d task done\n",num)
}
func main() {//Make client
c, err :=client.NewHTTPClient(client.HTTPConfig{
Addr:"http://localhost:8086",
Username: username,
Password: password,
})if err !=nil {
log.Fatalln("Error:", err)
}
_, err= queryDB(c, fmt.Sprintf("CREATE DATABASE %s", MyDB))if err !=nil {
log.Fatal(err)
}
i := 1
for i <= 10000{
defer writePoints(c,i)//fmt.Printf("i=%d\n",i)
i += 1}//fmt.Printf("task done : i=%d \n",i)
}
View Code
单读测试代码(query1.go):
package main
import ("log"
//"time"
"fmt"
//"math/rand"
"github.com/influxdata/influxdb/client/v2")const(
MyDB= "testInfluxdb"username= "root"password= "")
func queryDB(clnt client.Client, cmdstring) (res []client.Result, err error) {
q :=client.Query{
Command: cmd,
Database: MyDB,
}if response, err := clnt.Query(q); err ==nil {if response.Error() !=nil {returnres, response.Error()
}
res=response.Results
}else{returnres, err
}returnres, nil
}
func main() {//Make client
c, err :=client.NewHTTPClient(client.HTTPConfig{
Addr:"http://localhost:8086",
Username: username,
Password: password,
})if err !=nil {
log.Fatalln("Error:", err)
}
q := fmt.Sprintf("select * from monitorStatus where system_name='sys_5' and site_name='s_1' and equipment_name='e_6' order by time desc limit 10000 ;")
res, err2 :=queryDB(c, q)if err2 !=nil {
log.Fatal(err)
}
count := len(res[0].Series[0].Values)
log.Printf("Found a total of %v records\n", count)
}
View Code
测试结果记录
查看整体磁盘空间占用:
du -sh /var/lib/influxdb/
查看最终磁盘空间占用:
du -sh /var/lib/influxdb/data/testInfluxdb
100万条数据
[root@localhost goTest2]# time ./write1
real 0m14.594s
user 0m11.475s
sys 0m0.251s
[root@localhost goTest2]#time ./query12017/02/12 20:00:24 Found a total of 10000records
real 0m0.222s
user 0m0.052s
sys 0m0.009s
原始数据 : 28.6M
整体磁盘占用:27M
最终磁盘占用:21M
写入速度: 68521 / s
读取速度: 45045 / s
1000万条数据
[root@localhost goTest2]# time ./write1
real 2m22.520s
user 1m51.704s
sys 0m2.532s
[root@localhost goTest2]#time ./query12017/02/12 20:05:16 Found a total of 10000records
real 0m0.221s
user 0m0.050s
sys 0m0.003s
原始数据 : 286M
整体磁盘占用:214M
最终磁盘占用:189M 写入速度: 70165 / s
读取速度: 45249 / s
3000万条数据
[root@localhost goTest2]# time ./write1
real 7m19.121s
user 5m49.738s
sys 0m8.189s
[root@localhost goTest2]#lsquery1 query1.go write1 write1.go
[root@localhost goTest2]#time ./query12017/02/12 20:49:40 Found a total of 10000records
real 0m0.233s
user 0m0.050s
sys 0m0.012s
原始数据 : 858M
整体磁盘占用:623M
最终磁盘占用:602M
写入速度: 68318 / s
读取速度: 42918 / s
三、测试结果分析
整体磁盘占用情况对比:
最终磁盘占用情况对比:
写入速度对比:
读取速度对比:
结论:
相比MySQL来说,InfluxDB在磁盘占用和数据读取方面很占优势,而且随着数据规模的扩大,查询速度没有明显的下降。
针对时序数据来说,InfluxDB有明显的优势。
好,就这些了,希望对你有帮助。
inlfuxdb版本_InfluxDB和MySQL的读写对比测试相关推荐
- influxdb mysql对比_InfluxDB和MySQL的读写对比测试
今天进行了InfluxDB和MySQL的读写对比测试,这里记录下结果,也方便我以后查阅. 操作系统: CentOS6.5_x64 InfluxDB版本 : v1.1.0 MySQL版本:v5.1.73 ...
- inlfuxdb版本_InfluxDB安装及配置
这是我之前整理的InfluxDB安装及配置的笔记,这里记录下,也方便我以后查阅. 环境: CentOS6.5_x64 InfluxDB版本:1.1.0 一.安装 1.二进制安装 这里以centos6. ...
- mysql查询并设置高亮_Thinkphp3.2.3设置MySql主从读写分离后,简单调用主数据库查询
图/文:迷神 Thinkphp是一款不错的国产框架,使用范围广,应用也比较多.随着网站访问增大往往需要使用mysql主从同步功能,本身Thinkphp自带了主从读写分离的功能了. 但是我们经常有一个场 ...
- Centos7源码安装mysql及读写分离,互为主从
Linux服务器 -源码安装mysql 及读写分离,互为主从 一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...
- MySQL Router实现MySQL的读写分离
1.简介 MySQL Router是MySQL官方提供的一个轻量级MySQL中间件,用于取代以前老版本的SQL proxy. 既然MySQL Router是一个数据库的中间件,那么MySQL Rout ...
- mysql数据库读写文件
环境: centos7 mysql 5.6.47 用户:root@localhost 条件 mysql中涉及到读写操作,必然离不开secure_file_priv参数,它的值限制load data,s ...
- Mycat原理详解,Mycat 实现 MySQL 的读写分离(Mysql主从复制)
文章目录 1 Mycat 介绍 2 Mycat 安装 2.1下载安装JDK 2.2下载安装mycat 2.3启动和连接 3 Mycat 主要配置文件说明 4 利用 Mycat 实现 MySQL 的读写 ...
- MySQL注入读写文件、HTTP头中的SQL注入和cookie注入
MySQL注入读写文件 MySQL数据库在渗透过程中能够使用的功能还是比较多的,除了读取数据之外,还可以进行对文件进行读写(前提是权限足够) 读取前提: 1.用户权限足够高,尽量具有root权限 2. ...
- MYSQL+MYCAT读写分离实战
****1.实战MYSQL+MYCAT读写分离实战,实现MYSQL数据库1主2从架构.**2.写出MYSQL 1主2从架构部署过程和MYCAT实战全部过程,将所有部署过程写出来和划出架构图. 1.配置 ...
最新文章
- 李沐团队新作Gluon,复现CV经典模型到BERT,简单好用 | 强烈推荐
- 一步步揭开 原型链的面纱 面试再也不慌 原型链
- python 布尔值为f我的_python – 为什么我没有得到布尔值?
- Khadas VIM3 (Amlogic A311D) uboot去掉烦人的乱七八糟的打印1——BL2 BL3x
- 组态王接入多比物联网云平台
- jdbc oracle添加数据库连接,JDBC与Oracle数据库连接最常用方法
- 使用比较器的nulls对具有null值的列表进行排序
- [Linux]变量加减赋值以及将String转int
- 计算机专业毕业ppt怎么弄,计算机专业毕业生如何书写毕业论文.ppt
- 一个apply的实例
- [地产]“用90%的时间考虑失败”——李嘉诚(长江实业集团董事长)
- oracle 安装时的日志文件,oracle10g安装的日志文件 Oracle10g怎么查看操作日志
- js文件中可以写html吗,js代码写在HTML正常,分离成js文件再在HTML中引用不起作用...
- 网课答案搜题API接口使用
- 【星门跳跃】解题报告
- linux的sssd服务,sssd – 刷新ldap客户端配置Centos
- JAVA考试多选题判断得分
- 10、Hibernate的对象检索策略
- VScode调用KEIL-MDK
- 连夜干出来一个自动处理【支付宝交易支付投诉管理系统】,支持多商户
热门文章
- 数据库mysql表怎么设置外键_如何设置数据库中的外键
- 高通fastboot一键进9008工具_红米K30S至尊纪念版一键解锁bl获取面具root超详细刷机教程...
- 通俗理解tcp/ip的三次握手和四次分手
- EditText修改光标和背景色(绝对简单实用)
- 贵州2021高考体考成绩查询,2021年贵州体育专业考试成绩查询网址:http://www.eaagz.org.cn/...
- 图片上传压缩android,android 图片上传压缩常见问题分析
- html文本分类输出,构建中文网页分类器对网页进行文本分类
- 看完这个你还不理解右值引用和移动构造 你就可以来咬我(中)
- java工程师去字节飞书可以,字节跳动飞书Java后端开发暑假实习一面(过了)
- 奥迪坚为中民燃气打造专业便民服务呼叫中心