Skip to content

Commit

Permalink
Limit concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Sep 9, 2022
1 parent ee2d8f1 commit 4a0c9c6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,29 @@ public function batchFire($metric_array)
$batch_of = 40;
$batch = array_chunk($metric_array, $batch_of);

$x = 1;

/* Concurrency ++ */
foreach($batch as $key => $value) {
foreach($batch as $key => $value) {

$data['metrics'] = $value;

$promises = [
$key => $client->requestAsync('POST',$this->endPoint($metric_array[0]->type), ['form_params' => $data])
];

$x++;

if($x >= 10) {
$x = 1;
$this->sendPromise($promises);
}

}

$responses = Promise\Utils::unwrap($promises);
// $responses = Promise\Utils::unwrap($promises);



} catch (RequestException $e) {

Expand All @@ -125,6 +137,11 @@ public function batchFire($metric_array)

}

private function sendPromise($promises)
{
$responses = Promise\Utils::unwrap($promises);
// $responses = Promise\Utils::settle($promises)->wait();

}

}

0 comments on commit 4a0c9c6

Please sign in to comment.