Skip to content

Commit 97f7f54

Browse files
committed
MAGE-1109: rework safety margin
1 parent 6a8d1e5 commit 97f7f54

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Console/Command/BatchingOptimizeCommand.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ class BatchingOptimizeCommand extends AbstractStoreCommand
3232

3333
/**
3434
* Margin to ensure not to exceed maximum batch size when catalog is a mix between various product types
35-
* (i.e. with a lot of record sizes variations) - can be updated by the --margin option (from 0 to 10)
36-
* 0 => The recommended batch size will be almost equal to the strictly calculated maximum batch size
37-
* [1 to 9] => The more this value is, the more the recommended batch size will differ from the calculated maximum batch size
38-
* 10 => Highest possible value, the recommended batch size will be greatly lower than the calculated maximum batch size
35+
* (i.e. with a lot of record sizes variations) - can be updated by the --margin option (from 0.25 to 3.00)
36+
* 0.00 => Lowest possible value (0.00 * standard deviation = 0), the recommended batch size will be almost equal to the strictly calculated maximum batch size
37+
* 0.25 => Default value (0.25 * standard deviation), the recommended batch size will be close to the strictly calculated maximum batch size
38+
* 3.00 => Highest possible value (3 * standard deviation), the recommended batch size will be greatly lower than the calculated maximum batch size
3939
*/
40-
protected const DEFAULT_MARGIN = 1;
40+
protected const DEFAULT_MARGIN = 0.25;
41+
42+
/**
43+
* Min value for safety margin
44+
*/
45+
protected const MIN_MARGIN = 0;
4146

4247
/**
4348
* Max value for safety margin
4449
*/
45-
protected const MAX_MARGIN = 10;
50+
protected const MAX_MARGIN = 3;
4651

4752
/**
4853
* The sample size if the amount of products fetched to determine the recommended batch size
@@ -133,7 +138,7 @@ protected function getAdditionalDefinition(): array
133138
self::OPTION_MARGIN,
134139
'-' . self::OPTION_MARGIN_SHORTCUT,
135140
InputOption::VALUE_REQUIRED,
136-
'Safety margin - DEFAULT: ' . self::DEFAULT_MARGIN . ' - FROM 0 TO ' . self::MAX_MARGIN,
141+
'Safety margin - DEFAULT: ' . self::DEFAULT_MARGIN . ' - FROM ' . self::MIN_MARGIN . ' TO ' . self::MAX_MARGIN,
137142
)
138143
];
139144
}
@@ -181,11 +186,12 @@ protected function validateOptions(): void
181186
if (
182187
$this->input->getOption(self::OPTION_MARGIN)
183188
&& (
184-
!ctype_digit((string) $this->input->getOption(self::OPTION_MARGIN))
185-
|| (int) $this->input->getOption(self::OPTION_MARGIN) > self::MAX_MARGIN
189+
!is_numeric($this->input->getOption(self::OPTION_MARGIN))
190+
|| (float) $this->input->getOption(self::OPTION_MARGIN) > self::MAX_MARGIN
191+
|| (float) $this->input->getOption(self::OPTION_MARGIN) < self::MIN_MARGIN
186192
)
187193
) {
188-
throw new AlgoliaException("Margin option should be an integer (maximum 10)" );
194+
throw new AlgoliaException("Margin option should be a decimal value (between 0 and 3)" );
189195
}
190196
}
191197

@@ -420,10 +426,10 @@ protected function getEstimatedMaxBatchCount(int $averageSize): int
420426
*
421427
* @param int $averageSize
422428
* @param float $standardDeviation
423-
* @param int $margin
429+
* @param float $margin
424430
* @return int
425431
*/
426-
protected function getRecommendedBatchCount(int $averageSize, float $standardDeviation, int $margin = self::DEFAULT_MARGIN): int
432+
protected function getRecommendedBatchCount(int $averageSize, float $standardDeviation, float $margin = self::DEFAULT_MARGIN): int
427433
{
428434
return (int) (self::MAX_BATCH_SIZE_IN_BYTES / ($averageSize + $margin * $standardDeviation));
429435
}

0 commit comments

Comments
 (0)