carno-php /
pool
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Connections creating policy |
||
| 4 | * User: moyo |
||
| 5 | * Date: 2018/6/11 |
||
| 6 | * Time: 3:21 PM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Carno\Pool\Chips; |
||
| 10 | |||
| 11 | use Carno\Pool\Exceptions; |
||
| 12 | use Carno\Pool\Options; |
||
| 13 | |||
| 14 | trait CCPolicy |
||
| 15 | { |
||
| 16 | use ESJudger; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | private $swTimeouts = 0; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param Options $options |
||
| 25 | * @param string $identify |
||
| 26 | * @param int $idle |
||
| 27 | * @param int $busy |
||
| 28 | * @param int $waits |
||
| 29 | */ |
||
| 30 | protected function ccDecision(Options $options, string $identify, int $idle, int $busy, int $waits) : void |
||
| 31 | { |
||
| 32 | $current = Exceptions::happened($identify, Exceptions::SW_TIMEOUT); |
||
| 33 | |||
| 34 | if ($current > $this->swTimeouts) { |
||
| 35 | $increased = $current - $this->swTimeouts; |
||
| 36 | $this->swTimeouts = $current; |
||
| 37 | } |
||
| 38 | |||
| 39 | $score = $waits / $options->getWaitQMax; |
||
| 40 | $factor = (float) $options->scaleFactor; |
||
| 41 | $threshold = $factor / (($increased ?? 0) + 1); |
||
| 42 | |||
| 43 | if ($score < $threshold) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | ($target = $this->verdict($options, $idle, $busy)) && $this->resizing($target, 'policy-decision'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 48 | } |
||
| 49 | } |
||
| 50 |