今天进行了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 = 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;  
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-04-16
  • 2021-09-11
猜你喜欢
  • 2021-12-05
  • 2021-08-08
  • 2021-06-03
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案