【问题标题】:Influx DB write performance is too slowInfluxdb写入性能太慢
【发布时间】:2016-09-27 22:54:56
【问题描述】:

我正在使用 java 写入 influxDB。

假设 influxDB 实例与数据库连接。下面是我的代码。

influxDB.enableBatch(500, 100, TimeUnit.MICROSECONDS);
   while (true) {
            try {
        Point point = Point.measurement("cpu").addField("idle", (Math.random()*1000)).build();
        influxDB.write(dbName, "default", point);
                } catch (RuntimeException e) {
            System.out.println(e.getMessage());
    }
    }

通过使用这个逻辑,我每秒只能写入 300 条记录,这比我们预期的要少得多。每秒 2000 次写入就足够了。想知道我应该优化什么参数?

【问题讨论】:

    标签: java influxdb


    【解决方案1】:
    influxDB.enableBatch(500, 100, TimeUnit.MICROSECONDS);
    

    意味着您每 500 点或至少每 100 毫秒刷新一次。既然你说你每秒写 300 个点,我假设你根本不会在一秒钟内产生更多的点来写入 influxdb。

    我认为您“减慢”您的积分创建的部分是Math.random()。因此,尝试使用固定值并检查您现在是否在一秒钟内获得更多积分。

    在 influxdb-java github 上可以进行像您这样的性能测试。取自PerformanceTests.java,这个测试与你正在做的测试相当:

    @Test(threadPoolSize = 10, enabled = false)
    public void writeSinglePointPerformance() throws InterruptedException {
        String dbName = "write_" + System.currentTimeMillis();
        this.influxDB.createDatabase(dbName);
        this.influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
        String rp = TestUtils.defaultRetentionPolicy(this.influxDB.version());
        Stopwatch watch = Stopwatch.createStarted();
        for (int j = 0; j < SINGLE_POINT_COUNT; j++) {
            Point point = Point.measurement("cpu")
                    .addField("idle", (double) j)
                    .addField("user", 2.0 * j)
                    .addField("system", 3.0 * j).build();
            this.influxDB.write(dbName, rp, point);
        }
        this.influxDB.disableBatch();
        System.out.println("Single Point Write for " + SINGLE_POINT_COUNT + " writes of  Points took:" + watch);
        this.influxDB.deleteDatabase(dbName);
    }
    

    【讨论】:

    • 我正在为 (int i = 0; i
    • 您是否通过运行我发布的测试获得了更好的结果?如果不是,我认为除了在更好的硬件上尝试之外,您无能为力。
    • “SINGLE_POINT_COUNT”值为 100 万的上述代码需要 8 分钟才能执行。当我从 cpu 运行 select count(idle) 时,我只得到 789 条记录。这部分我不明白。
    • select * from cpu 为我提供了这些记录,其中包含许多跳过的数据时间空闲系统用户 2016-10-06T21:16:24.157Z 95 285 190 2016-10-06T21:16:24.158Z 276 828 552 2016-10-06T21:16:24.159Z 484 1452 968
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多