influx测试——单条读性能很差,大约400条/s,批量写性能很高,7万条/s,总体说来适合IOT数据批量存,根据tag查和过滤场景,按照时间顺序返回…

influx测试——单条读性能很差,大约400条/s,批量写性能很高,7万条/s,总体说来适合IOT数据批量存,根据tag查和过滤场景,按照时间顺序返回…

大家好,又见面了,我是全栈君。

测试准备

需要将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 := 1 * 10000
    rand.Seed(42)
    t := num
    bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
        Database:  MyDB,
        Precision: "us",
    })

    for i := 0; i < sampleSize; i++ {
        t += 1
        tags := 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)

}

 

单机读:

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[0].Series[0].Values)
    log.Printf("Found a total of %v records\n", count)

}

代码摘自:http://www.cnblogs.com/MikeZhang/p/InfluxDBTest20170212.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108515.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • qlineedit 不可编辑_qt中获取lineedit文本内容

    qlineedit 不可编辑_qt中获取lineedit文本内容1、设置不可编辑setReadOnly(false);//或setEnabled(false);//或setFocusPolicy(Qt::NoFocus);//无法获得焦点,自然无法输入,其他文本控件类似//或hasAcceptableInput(false);2.setPlaceholderText()设置提示文字如图,搜索输入框,没有输入任何字符时…

    2022年10月6日
    3
  • IMDG

    IMDG将内存作为首要存储介质不是什么新鲜事儿,在对主存的使用上,内存数据网格(InMemoryDataGrid,IMDG)与IMDB类似,但二者在架构上完全不同。IMDG特性可以总结为以下几点:数据

    2022年8月2日
    7
  • c++算法之最长递增子序列(LIS)

    c++算法之最长递增子序列(LIS)题目:输入一个整数n,随后输入n个整数,求这个长度为n的序列中严格递增的子序列的最长长度。例:输入:6143265输出:3解题思路:动态规划。将输入的序列存入一个数组v中,另外再定义一个数组a,用以存储以当前数字v[i]结尾时,最长递增子序列的长度是多少。定义数组时,全部初始化为1,初始状态表示的是最坏的情况,以v[i]结尾的最长递增子序列就是v[i]它本身,长度为1。接着将v[i]逐一…

    2022年6月3日
    31
  • How to pause the game in Uniy3D

    How to pause the game in Uniy3D

    2022年1月6日
    44
  • 浅析AnyCast网络技术「建议收藏」

    浅析AnyCast网络技术「建议收藏」什么是BGPAnyCast?BGPanycast就是利用一个(多个)as号码在不同的地区广播相同的一个ip段。利用bgp的寻路原则,短的aspath会选成最优路径(bgp寻路原则之n),从而优化了访问速度。其实bgpanycast是不同服务器用了相同的ip地址。阿里的DNS就是使用了BGPAnyCast“其实bgpanycast是不同服务器用了相同的ip地址。”言简意赅啊!D…

    2022年5月24日
    52
  • 海思Hi3798MV100机顶盒芯片介绍[通俗易懂]

    海思Hi3798MV100机顶盒芯片介绍[通俗易懂]Hi3798MV100是海思推出的专门针对OTT机顶盒市场的高性价比芯片方案。在码流兼容性、在线视频播放的流畅性、图像质量以及整机性能方面保持业界最好的用户体验。集成四核高性能处理器、内置NEON,其处理性能可以满足各种差异化的业务需求,支持Dolby和DTS音频处理。支持H.265、H.264、AVS+、MVC、MPEG2、MPEG4、VC-1、VP6、VP8等多种格式的高清视频解码和高性…

    2022年6月15日
    89

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号