今天进行了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
初始化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= 1486872962;
srand(time(NULL));
t=0;
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",0,NULL,0);
if (conn_ptr)
{
for(i=1;i<= 10000;i++)
{
mysql_query(conn_ptr,"begin");
for(j=0;j<N;j++,t++)
{
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);
return EXIT_SUCCESS;
}
可根据情况调整测试代码中的N参数。
单读测试代码(queryTest1.c):