Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created memory efficient iterator for importexport_importdata table #10918

Closed
wants to merge 3 commits into from
Closed

Conversation

diwipl
Copy link

@diwipl diwipl commented Sep 17, 2017

Default iterator for importexport_importdata table was loading whole table contents to memory, resulting in huge memory usage when importing large numbers of products.

Description

Additional iterator was created. It gets all rows ids from table and then uses them to return "current" row in memory optimized way.

Fixed Issues (if relevant)

  1. Huge memory usage when importing large quantities of products #10914: Huge memory usage when importing large quantities of products

Manual testing scenarios

  1. 1 500 000 entities import should easily run on 8GB RAM server

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Sep 17, 2017

CLA assistant check
All committers have signed the CLA.

/**
* Iterator constructor.
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
* @param null $connectionName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hint for this parameter should be string as in parent constructor

) {
parent::__construct($context, $connectionName);

$this->rowsIds = $this->getRowsIds();
Copy link
Contributor

@ishakhsuvarov ishakhsuvarov Sep 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Magento Technical Guidelines it is strongly discouraged to perform any operations in the constructor of the class with the exception of Dependency Assignment and Dependency Validation operations.
Implementing business logic inside the constructor violates single-responsibility principle, generally makes code more error-prone and harder to test.

/**
* Import data iterator
*/
class Iterator extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this iterator may be decomposed into actual iterator and resource model which provides data to the iterator. Current implementation has multiple responsibilities which does not follow SOLID principles.

}

return $iterator;
return $this->iteratorFactory->create();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterator factory should produce \Iterator objects accodring to the method docblock

/**
* Import data iterator
*/
class Iterator extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should implement \Iterator

@ishakhsuvarov ishakhsuvarov added this to the September 2017 milestone Sep 17, 2017
* @param string $connectionName
* @param array $arguments
*/
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\ImportExport\Model\ResourceModel\Import\Data\IteratorFactory $iteratorFactory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* DataProvider for import data
*/
class DataProvider extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name classes properly, not a word-per-folder.

/**
* Import data iterator
*/
class Iterator implements \Iterator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name classes properly, not a word-per-folder.

@magento-engcom-team magento-engcom-team changed the base branch from develop to 2.3-develop October 20, 2017 15:32
@orlangur
Copy link
Contributor

Hi @diwipl, are you going to continue work on this PR?

@diwipl
Copy link
Author

diwipl commented Oct 26, 2017

Yes, I will. Sorry for the delay.

@okorshenko okorshenko modified the milestones: October 2017, November 2017 Nov 1, 2017
@ishakhsuvarov ishakhsuvarov removed their assignment Nov 9, 2017
@orlangur
Copy link
Contributor

Closing due to inactivity. Feel free to reach me out anytime later if you wish to continue work on pull request and it will be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants