Created
June 10, 2019 12:56
-
-
Save michalspondr/1635e968d1e50c0c10fabe238e11f6b3 to your computer and use it in GitHub Desktop.
Performance test of writing to InfluxDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "include/InfluxDBFactory.h" | |
#include "include/Transport.h" | |
#include "include/Point.h" | |
using namespace influxdb; | |
int main() { | |
const std::size_t batch_size = 15000; | |
int point_count = 54000000; // number of write points | |
int counter = 0; | |
// initialize database | |
auto db = InfluxDBFactory::Get("http://localhost:8086/write?db=cpptest"); | |
db->enableBuffering(batch_size); | |
// push all write points to database | |
while (point_count) { | |
db->write(Point{"M2"}.addField("intvalue", 10).addField("strvalue", "randstring").addTag("machine", "machine")); | |
db->write(Point{"ME2"}.addField("intvalue", 10).addField("strvalue", "randstring").addTag("machine", "machine")); | |
db->write(Point{"asssembled_layout_intance"}.addField("intvalue", 10).addField("strvalue", "randstring").addTag("machine", "machine")); | |
db->write(Point{"machine_assembly"}.addField("intvalue", 10).addField("strvalue", "randstring").addTag("machine", "machine")); | |
db->write(Point{"reject_rate"}.addField("intvalue", 10).addField("strvalue", "randstring").addTag("machine", "machine")); | |
counter += 5; | |
point_count -= 5; | |
if (! (counter % batch_size)) { | |
std::cout << "flushing... " << point_count << std::endl; | |
db->flushBuffer(); // flush | |
counter = 0; | |
} | |
} | |
db->flushBuffer(); // flush if necessary | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment