今天进行了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 DATABASE testMysql;
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 <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "mysql/mysql.h" #define N 100 int main()
{
MYSQL *conn_ptr;
int res;
int t,i,j;
int64_t tstamp = ;
srand(time(NULL));
t=;
conn_ptr = mysql_init(NULL);
if (!conn_ptr)
{
printf("mysql_init failed\n");
return EXIT_FAILURE;
}
conn_ptr = mysql_real_connect(conn_ptr,"localhost","root","","testMysql",,NULL,);
if (conn_ptr)
{
for(i=;i<= ;i++)
{
mysql_query(conn_ptr,"begin");
for(j=;j<N;j++,t++)
{
char query[]={}; 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%,(t+i)%,(t+j)%,rand()%,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% == ) tstamp+=;
}
mysql_query(conn_ptr,"commit");
//printf("i=%d\n",i);
}
}
else
{
printf("Connection failed\n");
}
mysql_close(conn_ptr);
return EXIT_SUCCESS;
}

可根据情况调整测试代码中的N参数。

单读测试代码(queryTest1.c):

#include <stdio.h>
#include <stdlib.h>
#include "mysql/mysql.h" int main()
{
MYSQL *conn_ptr;
MYSQL_RES *res_ptr;
MYSQL_ROW sqlrow;
MYSQL_FIELD *fd;
int res, i, j; conn_ptr = mysql_init(NULL);
if (!conn_ptr)
{
return EXIT_FAILURE;
}
conn_ptr = mysql_real_connect(conn_ptr,"localhost","root","","testMysql", , NULL, );
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 = ; 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);
return EXIT_SUCCESS;
}

Makefile文件:

all:
gcc -g insertTest1.c -o insertTest1 -L/usr/lib64/mysql/ -lmysqlclient
gcc -g queryTest1.c -o queryTest1 -L/usr/lib64/mysql/ -lmysqlclient clean:
rm -rf insertTest1
rm -rf queryTest1

测试数据记录

磁盘空间占用查询:

使用du方式(新数据库,仅为测试):

du -sh /var/lib/mysql

查询特定表:

use information_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 ./queryTest1
    Rows 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 ./queryTest1
    Rows 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 ./queryTest1
    Rows 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, cmd string) (res []client.Result, err error) {
q := client.Query{
Command: cmd,
Database: MyDB,
}
if response, err := clnt.Query(q); err == nil {
if response.Error() != nil {
return res, response.Error()
}
res = response.Results
} else {
return res, err
}
return res, nil
} func writePoints(clnt client.Client,num int) {
sampleSize := *
rand.Seed()
t := num
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
Database: MyDB,
Precision: "us",
}) for i := ; i < sampleSize; i++ {
t +=
tags := map[string]string{
"system_name": fmt.Sprintf("sys_%d",i%),
"site_name":fmt.Sprintf("s_%d", (t+i) % ),
"equipment_name":fmt.Sprintf("e_%d",t % ),
}
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 :=
for i <= {
defer writePoints(c,i)
//fmt.Printf("i=%d\n",i)
i +=
}
//fmt.Printf("task done : i=%d \n",i) }

单读测试代码(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, cmd string) (res []client.Result, err error) {
q := client.Query{
Command: cmd,
Database: MyDB,
}
if response, err := clnt.Query(q); err == nil {
if response.Error() != nil {
return res, response.Error()
}
res = response.Results
} else {
return res, err
}
return res, 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[].Series[].Values)
log.Printf("Found a total of %v records\n", count) }

测试结果记录

查看整体磁盘空间占用:

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 ./query1
    // :: Found a total of records 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 ./query1
    // :: Found a total of records 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]# ls
    query1 query1.go write1 write1.go
    [root@localhost goTest2]# time ./query1
    // :: Found a total of records real 0m0.233s
    user 0m0.050s
    sys 0m0.012s

    原始数据 : 858M
    整体磁盘占用:623M
    最终磁盘占用:602M
    写入速度: 68318 / s
    读取速度: 42918 / s

三、测试结果分析

整体磁盘占用情况对比:

最终磁盘占用情况对比:

写入速度对比:

读取速度对比:

结论:

相比MySQL来说,InfluxDB在磁盘占用和数据读取方面很占优势,而且随着数据规模的扩大,查询速度没有明显的下降。
针对时序数据来说,InfluxDB有明显的优势。

好,就这些了,希望对你有帮助。

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017/20170212_InfluxDB和MySQL的读写对比测试.md

欢迎补充

InfluxDB读写性能测试的更多相关文章

  1. Linux系统性能测试工具(九)——文件系统的读写性能测试工具之iozone

    本文介绍关于Linux系统(适用于centos/ubuntu等)的文件系统的读写性能测试工具-iozone: 参考链接: https://www.cnblogs.com/Dev0ps/p/788938 ...

  2. 使用iozone进行磁盘读写性能测试

    对于很多GIS工程师,经常需要对系统的磁盘性能进行测试,为了排查问题或者帮助用户进行系统设计. IOZone这个磁盘性能测试工具就是一个很方便的辅助工具. 下面就以个测试共享目录的读写性能为例,说明其 ...

  3. Cassandra读写性能测试

    1. 测试目的 测试Cassandra集群读写TPS的极值,确定Cassandra读写性能. 2. 测试环境 2.1 硬件信息 CPU 8核 Intel(R) Xeon(R) CPU E5-2650 ...

  4. linux 磁盘读写性能测试

    1. 测试读取速度 haparm -Tt /dev/xxx 1.1 获取硬盘设备名称: fdisk -l Disk /dev/xvdf: 365.0 GB, 365041287168 bytes 25 ...

  5. jmeter+influxdb+grafana性能测试监控

    背景: 话说Jmeter原生的监控确实太丑了,听大佬们在讨论Jmeter+InfluxDb+Grafana的监控,于是,为了有一个漂亮的测试报告,就手动开始进行部署. 安装步骤: 1.influxdb ...

  6. OpenWrt中对USB文件系统的操作, 以及读写性能测试

    参考 http://h-wrt.com/en/doc/flash 1. 查看usb存储在启动日志中的信息 # dmesg [ 5.720000] usbcore: registered new int ...

  7. [eMMC]eMMC读写性能测试

    读写速率(dd) https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/ eMMC健康情况(mm ...

  8. java对比IO和NIO的文件读写性能测试

    1. NIO采用更接近操作系统执行IO的方式:通道和缓存器:顾名思义,数据源的数据由缓存器通过通道进行传输. 2. 在JDK5之后,原始IO系统底层用NIO进行了优化,这可以通过sun公布的源码中找到 ...

  9. Glusterfs读写性能测试与分析

    一.测试目的: 1.测试分布卷(Distributed).分布式复制卷(Distributed-Replicate).条带卷(Strip)和分布式条带复制卷(Distributed-Strip-Rep ...

随机推荐

  1. 关于ios 推送功能的终极解决

    刚刚做了一个使用推送功能的应用 遇到了一些问题整的很郁闷 搞了两天总算是弄明白了 特此分享给大家 本帖 主要是针对产品发布版本的一些问题 综合了网上一些资料根据自己实践写的 不过测试也可以看看 首先要 ...

  2. 7 -- Spring的基本用法 -- 12...

    7.12 Spring 3.0 提供的表达式语言(SpEL) Spring表达式语言(简称SpEL)是一种与JSP 2 的EL功能类似的表达式语言,它可以在运行时查询和操作对象图.支持方法调用和基本字 ...

  3. 查看错误日志发现有两个警告(ignored in --skip-name-resolve mode)

    2016-08-02 17:30:26 17374 [Warning] 'user' entry '@losnau-223.com' ignored in --skip-name-resolve mo ...

  4. node.js 下依赖Express 实现post 4种方式提交参数

    上面这个图好有意思啊,哈哈, v8威武啊.... 在2014年的最后一天和大家分享关于node.js 如何提交4种格式的post数据. 上上一篇说到了关于http协议里定义的4种常见数据的post方法 ...

  5. Eclipse发布Maven项目到远程服务器

    pom.xml中的配置依赖有两种: 一.tomcat-maven.plugin <plugin> <groupId>org.codehaus.mojo</groupId& ...

  6. 深度学习caffe:Ubuntu16.04安装指南(1)

    caffe [CPU ONLY] 2017-01-15 最简单的安装配置方式: 不用GPU加速,使用OPENCV2.4图像库, 这是根据官方教程(链接如下)简化而得到. Ubuntu 16.04 or ...

  7. 安卓异步任务AsynTask(1)

    1.AsynTask类结构asysTask类主要用到的几个内部回调函数有:doInBackGround() onPreExecute() onPostExecute() onProgressUpdat ...

  8. 4、安卓数据存储——sqlite

    朋友圈里的每一个消息体里面的数据,当下拉刷新从服务器下载数据包后,存入sqlite:用户名.图片url.点赞.评论等等.上拉加载的时候,从数据库里取出最近的5条数据加载到朋友圈上. Android通过 ...

  9. 分享Grunt.js配置: watch + liveReload 实时监测文件变化自动刷新浏览器

    http://www.tuicool.com/articles/2eaQJn 用Grunt配置watch和liveReload组件,可以实时检测指定的文件变化并自动刷新浏览器.目前基本已经成为了我的必 ...

  10. 前端制作篇之meta标签篇

    移动端前端制作有些地方不同于互联网,这篇主要讨论的是meta标签.meta标签位于之间.是主要辅助HTML结构层的.meta标签不管在互联网前端还是在移动端都起了很重要的作用.这里只讨论移动端. 附上 ...