Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Improve batch write (#27)
Browse files Browse the repository at this point in the history
* Improve batch write

* Update README.md
  • Loading branch information
awegrzyn authored Jul 30, 2019
1 parent b12ecc9 commit 684b355
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,56 @@


InfluxDB C++ client library
- Writing data
- Writing points
- Batch write
- ~~Data exploration~~
- Supported transports: HTTP/HTTPS with Basic Auth, UDP and Unix datagram socket
- Supported transports
- HTTP/HTTPS with Basic Auth
- UDP
- Unix datagram socket


### Installation

__Build requirements:__
g++ 6.0+, CMake 3.12+

__Dependencies:__
cURL, boost 1.57+ (optional)

__Compilation__
```bash
git clone https://github.com/awegrzyn/influxdb-cxx.git
cd influxdb-cxx; mkdir build
cmake -H. -Bbuild
cmake --build build
sudo make -C build install
```

## Quick start

### Basic usage

```cpp
/// Provide complete URI
// Provide complete URI
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/write?db=test");
influxdb->write(Point{"test"}
.addField("value", 10)
.addTag("host", "localhost")
);
```

### Installation
### Batch write

__Build requirements:__
- g++ 6.0+
- CMake 3.12+
- cURL
- boost 1.57+ (optional for UDP and Unix socket transports)
```cpp
// Provide complete URI
auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086/write?db=test");
// Write batches of 100 points
influxdb->batchOf(100);

```bash
git clone https://github.com/awegrzyn/influxdb-cxx.git
cd influxdb-cxx; mkdir build
cmake -H. -Bbuild
cmake --build build
sudo make -C build install
for (;;) {
influxdb->write(Point{"test"}.addField("value", 10));
}
```
## Transports
Expand Down
2 changes: 1 addition & 1 deletion include/InfluxDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InfluxDB

/// Enables metric buffering
/// \param size
void enableBuffering(const std::size_t size = 32);
void batchOf(const std::size_t size = 32);

/// Adds a global tag
/// \param name
Expand Down
2 changes: 1 addition & 1 deletion src/InfluxDB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ InfluxDB::InfluxDB(std::unique_ptr<Transport> transport) :
{
}

void InfluxDB::enableBuffering(const std::size_t size)
void InfluxDB::batchOf(const std::size_t size)
{
mBufferSize = size;
mBuffering = true;
Expand Down
8 changes: 4 additions & 4 deletions test/benchmark.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ int main(int argc, char* argv[]) {
("url", boost::program_options::value<std::string>()->required(), "URL to InfluxDB database")
("buffer", boost::program_options::value<int>(), "Buffer size");

boost::program_options::variables_map vm;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

auto db = InfluxDBFactory::Get(vm["url"].as<std::string>());

if (vm.count("count")) {
count = std::floor(vm["count"].as<int>()/2) + 1;
}

if (vm.count("buffer")) {
db->enableBuffering(vm["buffer"].as<int>());
db->batchOf(vm["buffer"].as<int>());
}

for(int i = 0; i <= count; i++) {
Expand Down
9 changes: 9 additions & 0 deletions test/testFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ BOOST_AUTO_TEST_CASE(test)
);
}

BOOST_AUTO_TEST_CASE(test2)
{
auto influxdb = influxdb::InfluxDBFactory::Get("udp://localhost:8084");
influxdb->batchOf(2);
influxdb->write(Point{"test"}.addField("value", 10));
influxdb->write(Point{"test"}.addField("value", 10));
influxdb->write(Point{"test"}.addField("value", 10));
}

} // namespace test
} // namespace influxdb

0 comments on commit 684b355

Please sign in to comment.