Skip to content

OOM/Timeouts when saving a category with large catalog as all product URLs are regenerated #7874

@devonto

Description

@devonto

With a catalog of many thousands of products loaded, saving a category causes long execution times and high memory usage, when it isn't necessarily required. In a production environment, the execution fails with max_execution_time or memory_limit errors.

It appears that the system is trying to regenerate all URLs of products contained within the category and subcategories; even if the url_key is not modified.

Preconditions

  1. Magento 2.1.1
  2. max_execution_time set to 300
  3. memory_limit set to 2G
  4. Catalog of 140,000 products
  5. Top category which contains subcategories and 40,000+ products

Steps to reproduce

  1. Simply "Save" the top category without even making any changes

Expected result

  1. No errors
  2. A notice of You saved the category should appear

Actual result

  1. PHP errors for max_execution_time and/or memory_limit

A workaround is to modify /vendor/magento/module-catalog-url-rewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php temporarily to return; on line 1 of the execute() function to prevent URL rewrite changes.

A suggested performance improvement would be to check if the url_key was modified before running the regeneration of URLs.

This, though, cannot be used if the url_key is updated. At that point, the process should be handled by some background task.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions