Problem/Motivation
With a lot of entries in the xmlsitemap table, we have ~450,000, running drush xmlsitemap:regenerate hits memory errors on the latest 8.x-1.x-dev. I'm using Drush 9, enabled by this patch:
https://www.drupal.org/project/xmlsitemap/issues/2968172#comment-12770930 β
.
Here is the error and stack I hit, again this is not happening on alpha2, just the latest 8.x-1.x-dev
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 1041145856) (tried to allocate 20480 bytes) in /var/www/vendor/drush/drush/includes/preflight.inc on line 54
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/drush/drush/drush:0
PHP 2. require() /var/www/vendor/drush/drush/drush:4
PHP 3. Drush\Runtime\Runtime->run($argv = *uninitialized*) /var/www/vendor/drush/drush/drush.php:66
PHP 4. Drush\Runtime\Runtime->doRun($argv = *uninitialized*) /var/www/vendor/drush/drush/src/Runtime/Runtime.php:41
PHP 5. Drush\Application->run($input = *uninitialized*, $output = *uninitialized*) /var/www/vendor/drush/drush/src/Runtime/Runtime.php:112
PHP 6. Drush\Application->doRun($input = *uninitialized*, $output = *uninitialized*) /var/www/vendor/symfony/console/Application.php:148
PHP 7. Drush\Application->doRunCommand($command = *uninitialized*, $input = *uninitialized*, $output = *uninitialized*) /var/www/vendor/symfony/console/Application.php:248
PHP 8. Consolidation\AnnotatedCommand\AnnotatedCommand->run($input = *uninitialized*, $output = *uninitialized*) /var/www/vendor/symfony/console/Application.php:964
PHP 9. Consolidation\AnnotatedCommand\AnnotatedCommand->execute($input = *uninitialized*, $output = *uninitialized*) /var/www/vendor/symfony/console/Command/Command.php:251
PHP 10. Consolidation\AnnotatedCommand\CommandProcessor->process($output = *uninitialized*, $names = *uninitialized*, $commandCallback = *uninitialized*, $commandData = *uninitialized*) /var/www/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:404
PHP 11. Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter($names = *uninitialized*, $commandCallback = *uninitialized*, $commandData = *uninitialized*) /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:150
PHP 12. Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback($commandCallback = *uninitialized*, $commandData = *uninitialized*) /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:181
PHP 13. call_user_func_array:{/var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:235}(*uninitialized*, *uninitialized*) /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:235
PHP 14. Drupal\xmlsitemap\Commands\XmlSitemapCommands->regenerate(*uninitialized*) /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:235
PHP 15. xmlsitemap_run_unprogressive_batch(*uninitialized*) /var/www/web/modules/contrib/xmlsitemap/src/Commands/XmlSitemapCommands.php:77
PHP 16. batch_process($redirect = *uninitialized*, $url = *uninitialized*, $redirect_callback = *uninitialized*) /var/www/web/modules/contrib/xmlsitemap/xmlsitemap.module:1481
PHP 17. _batch_process() /var/www/web/core/includes/form.inc:880
PHP 18. xmlsitemap_regenerate_batch_generate($smid = *uninitialized*, $context = *uninitialized*) /var/www/web/core/includes/batch.inc:294
PHP 19. Drupal\xmlsitemap\XmlSitemapGenerator->regenerateBatchGenerate($smid = *uninitialized*, $context = *uninitialized*) /var/www/web/modules/contrib/xmlsitemap/xmlsitemap.module:2473
PHP 20. Drupal\xmlsitemap\XmlSitemapGenerator->generatePage($sitemap = *uninitialized*, $page = *uninitialized*) /var/www/web/modules/contrib/xmlsitemap/src/XmlSitemapGenerator.php:320
PHP 21. Drupal\xmlsitemap\XmlSitemapWriter->generateXML() /var/www/web/modules/contrib/xmlsitemap/src/XmlSitemapGenerator.php:192
PHP 22. Drupal\xmlsitemap\XmlSitemapGenerator->generateChunk($sitemap = *uninitialized*, $writer = *uninitialized*, $chunk = *uninitialized*) /var/www/web/modules/contrib/xmlsitemap/src/XmlSitemapWriter.php:160
PHP 23. Drupal\Core\Url::fromUri($uri = *uninitialized*, $options = *uninitialized*) /var/www/web/modules/contrib/xmlsitemap/src/XmlSitemapGenerator.php:247
PHP 24. Drupal\Core\Url::fromInternalUri($uri_parts = *uninitialized*, $options = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Url.php:307
PHP 25. Drupal\Core\Path\PathValidator->getUrlIfValidWithoutAccessCheck($path = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Url.php:415
PHP 26. Drupal\Core\Path\PathValidator->getUrl($path = *uninitialized*, $access_check = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Path/PathValidator.php:89
PHP 27. Drupal\Core\Path\PathValidator->getPathAttributes($path = *uninitialized*, $request = *uninitialized*, $access_check = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Path/PathValidator.php:122
PHP 28. Drupal\Core\Routing\Router->match($pathinfo = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Path/PathValidator.php:163
PHP 29. Drupal\Core\Routing\Router->matchRequest($request = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Routing/Router.php:116
PHP 30. Drupal\Core\Routing\Router->applyRouteEnhancers($defaults = *uninitialized*, $request = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Routing/Router.php:130
PHP 31. Drupal\Core\Routing\Enhancer\ParamConversionEnhancer->enhance($defaults = *uninitialized*, $request = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Routing/Router.php:259
PHP 32. Drupal\Core\ParamConverter\ParamConverterManager->convert($defaults = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php:45
PHP 33. Drupal\Core\ParamConverter\EntityConverter->convert($value = *uninitialized*, $definition = *uninitialized*, $name = *uninitialized*, $defaults = *uninitialized*) /var/www/web/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php:100
PHP 34. Drupal\node\NodeStorage->load($id = *uninitialized*) /var/www/web/core/lib/Drupal/Core/ParamConverter/EntityConverter.php:103
PHP 35. Drupal\node\NodeStorage->loadMultiple($ids = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:249
PHP 36. Drupal\node\NodeStorage->doLoadMultiple($ids = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:279
PHP 37. Drupal\node\NodeStorage->getFromPersistentCache($ids = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:356
PHP 38. Drupal\Core\Cache\DatabaseBackend->getMultiple($cids = *uninitialized*, $allow_invalid = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:941
PHP 39. Drupal\Core\Cache\DatabaseBackend->prepareItem($cache = *uninitialized*, $allow_invalid = *uninitialized*) /var/www/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php:122
PHP 40. unserialize(*uninitialized*) /var/www/web/core/lib/Drupal/Core/Cache/DatabaseBackend.php:167
PHP 41. drush_shutdown() /var/www/vendor/drush/drush/includes/preflight.inc:0
PHP 42. error_get_last() /var/www/vendor/drush/drush/includes/preflight.inc:54
Proposed resolution
Investigate what the cause of the memory issues are. Perhaps introduce queuing or something to chunk the work?
Remaining tasks
- Identify the memory issues
- Implement a work around and/or bring down memory requirements
User interface changes
None
API changes
Mayyyybe
Data model changes
Mayyyybe