Skip to content

Failure to allocate memory error when importing customers in admin #8851

Closed
@kevin-carroll-cl

Description

@kevin-carroll-cl

When importing customers into a site with a large number of existing customers through the standard Magento importer tool (System > Data Transfer > Import), with Entity Type: Customers Main File, and Import Behavior: Add/Update Complex Data, the import POST returns a 500 status caused by exceeding allowed memory limits.

Preconditions

  1. Magento Enterprise 2.1.4
  2. Server is running PHP version 7.0.15
  3. Memory limit is set to the standard 768 MB
  4. The target store already has a large number of customers (eg 250k+, we experience it at 261,659)

Steps to reproduce

  1. In admin, go to SYSTEM > Import
  2. Set Entity Type to: Customers Main File
  3. Set Import Behavior to: Add/Update Complex Data
  4. Select a valid import CSV with at least 1 customer row, and select Check Data
  5. After data validates, select Import

Expected result

  1. Customer data should be imported

Actual result

  1. Import Screen loader never expires & Import POST responds with status code 500:
  2. Server error log shows a corresponding PHP Fatal error:

PHP Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 20480 bytes) in /server/sites/(SITE)/vendor/magento/framework/Model/ResourceModel/Db/VersionControl/Snapshot.php on line 47, referer: https://(SITE)/backend/admin/import/
ImportError.txt

The memory use appears to be mainly triggered by framework level code (\Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot::registerSnapshot), and is likely platform independent.

Through profiling and debugging we have found 2 very expensive processes that seem to be contributing to this. When beginning the customer import, \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::getCustomerId is called, which triggers \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::load to execute which in turn executes \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIterator::iterate. Through this process every existing customer account is retrieved and loaded, which is a costly procedure to begin with, but then the email, website id and customer ids are loaded into a multidimensional array. Additionally, loading the customer array as part of the CollectByPagesIterator::iterate method, triggers snapshotting every customer and loading the whole entity data into another in memory array.

Every existing customer is loaded and initialized as a full customer entity object, and data is held in multiple in-memory locations, in order to import a relatively small collection of new customers. This is an unsustainable practice, is costly in time, processing, and memory, and it is difficult to see the value in doing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ImportExportIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions