-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improved documentation about batching, WriteOptions, WriteType …
…should be in separate file (#24)
- Loading branch information
Showing
6 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Shows how to use batching for more performance writes. | ||
*/ | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use InfluxDB2\Client; | ||
use InfluxDB2\WriteType as WriteType; | ||
|
||
$organization = 'my-org'; | ||
$bucket = 'my-bucket'; | ||
$token = 'my-token'; | ||
|
||
$client = new Client([ | ||
"url" => "http://localhost:9999", | ||
"token" => $token, | ||
"bucket" => $bucket, | ||
"org" => $organization, | ||
"precision" => InfluxDB2\Model\WritePrecision::S | ||
]); | ||
|
||
print "*** Write by batching ***\n"; | ||
|
||
$writeApi = $client->createWriteApi( | ||
["writeType" => WriteType::BATCHING, 'batchSize' => 1000, "flushInterval" => 1000]); | ||
|
||
foreach (range(1, 10000) as $number) { | ||
$writeApi->write("mem,host=aws_europe,type=batch value=1i $number"); | ||
} | ||
|
||
// flush remaining data | ||
$client->close(); | ||
|
||
print "*** Check result ***\n"; | ||
|
||
$queryApi = $client->createQueryApi(); | ||
$query = "from(bucket: \"$bucket\") | ||
|> range(start: 0) | ||
|> filter(fn: (r) => r[\"_measurement\"] == \"mem\") | ||
|> filter(fn: (r) => r[\"host\"] == \"aws_europe\") | ||
|> count()"; | ||
$tables = $queryApi->query($query); | ||
$record = $tables[0]->records[0]; | ||
$value = $record->getValue(); | ||
print "Count: $value\n"; | ||
|
||
$client->close(); | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace InfluxDB2; | ||
|
||
class WriteOptions | ||
{ | ||
const DEFAULT_BATCH_SIZE = 10; | ||
const DEFAULT_FLUSH_INTERVAL = 1000; | ||
|
||
public $writeType; | ||
public $batchSize; | ||
public $flushInterval; | ||
|
||
/** | ||
* WriteOptions constructor. | ||
* $writeOptions = [ | ||
* 'writeType' => methods of write (WriteType::SYNCHRONOUS - default, WriteType::BATCHING) | ||
* 'batchSize' => the number of data point to collect in batch | ||
* 'flushInterval' => flush data at least in this interval | ||
* ] | ||
* @param array $writeOptions Array containing the write parameters (See above) | ||
*/ | ||
public function __construct(array $writeOptions = null) | ||
{ | ||
//initialize with default values | ||
$this->writeType = $writeOptions["writeType"] ?: WriteType::SYNCHRONOUS; | ||
$this->batchSize = $writeOptions["batchSize"] ?: self::DEFAULT_BATCH_SIZE; | ||
$this->flushInterval = $writeOptions["flushInterval"] ?: self::DEFAULT_FLUSH_INTERVAL; | ||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace InfluxDB2; | ||
|
||
class WriteType | ||
{ | ||
const SYNCHRONOUS = 1; | ||
const BATCHING = 2; | ||
} |