Skip to content

Commit 01da000

Browse files
author
Stanislav Idolov
committed
MAGETWO-64187: Batch size algorithm
1 parent 59ce6dd commit 01da000

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
88

9+
/**
10+
* Ensure that size of index MEMORY table is enough for configured rows count in batch.
11+
*/
912
class BatchSizeCalculator
1013
{
1114
/**

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
1010

11+
/**
12+
* Estimate index memory size for largest composite product in catalog.
13+
*/
1114
class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
1215
{
1316
/**

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/IndexTableRowSizeEstimator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
88

9+
/**
10+
* Estimate index memory size for simple product.
11+
* Size depends on websites and customer groups count.
12+
*/
913
class IndexTableRowSizeEstimator implements \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface
1014
{
1115
/**

lib/internal/Magento/Framework/Indexer/BatchSizeManagement.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Framework\Indexer;
88

9+
/**
10+
* Class set MEMORY table size for indexer processes according batch size and index row size.
11+
*/
912
class BatchSizeManagement implements \Magento\Framework\Indexer\BatchSizeManagementInterface
1013
{
1114
/**
@@ -28,14 +31,13 @@ public function __construct(
2831
*/
2932
public function ensureBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $batchSize)
3033
{
31-
// Calculate memory table size for product
32-
$memoryForLargeComposite = $this->rowSizeEstimator->estimateRowSize();
34+
$rowMemory = $this->rowSizeEstimator->estimateRowSize();
3335

3436
$maxHeapTableSize = $connection->fetchOne('SELECT @@max_heap_table_size;');
3537
$tmpTableSize = $connection->fetchOne('SELECT @@tmp_table_size;');
3638
$maxMemoryTableSize = min($maxHeapTableSize, $tmpTableSize);
3739

38-
$size = (int) ($memoryForLargeComposite * $batchSize);
40+
$size = (int) ($rowMemory * $batchSize);
3941

4042
if ($maxMemoryTableSize < $size) {
4143
$connection->query('SET SESSION tmp_table_size = ' . $size . ';');

lib/internal/Magento/Framework/Indexer/BatchSizeManagementInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* Batch size manager can be used to ensure that MEMORY table has enough memory for data in batch.
12+
* @api
1213
*/
1314
interface BatchSizeManagementInterface
1415
{

lib/internal/Magento/Framework/Indexer/IndexTableRowSizeEstimatorInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
namespace Magento\Framework\Indexer;
88

9+
/**
10+
* Calculate memory size for entity according different dimensions.
11+
* @api
12+
*/
913
interface IndexTableRowSizeEstimatorInterface
1014
{
1115
/**
12-
* Calculate memory size for product row.
16+
* Calculate memory size for entity row.
1317
*
1418
* @return float
1519
*/

0 commit comments

Comments
 (0)