batch process fails to start new thread after reaching 50% of available memory
When executing a drush batch-process, it does not restart after the available memory fills up. Is this a bug?
Using migrate-import, the new thread start works fine.
Prepared 153480 out of 206941 [3034.35 sec, 512.28 MB] [ok]
Batch process has consumed in excess of 50% of available memory. Starting new thread [3034.35 sec, 512.27 MB] [batch]
Returned from hook drush_core_batch_process [3034.35 sec, 512.26 MB] [debug]
Command dispatch complete [3034.35 sec, 512.2 MB] [notice]
Timer Cum (sec) Count Avg (msec)
page 3034.013 1 3034013.05
sounds like a bug ... what version of drush? please provide steps to reproduce, if possible.
Drush Version : 8.1.13
This issue happens with all of my drush batch-process -es. I just figured out today with debug and verbose calls where it fails. For now I am running drush batch process in a for loop. Have not yet tried on other systems.
PS I found a somewhat related issue, although I done all that they describe in this thread https://drupal.stackexchange.com/questions/110195/drush-crashes-after-command-dispatch-complete and I am not getting any php errors.
Perhaps @pfrenssen has an idea about this as he recently touched the batch code..
This doesn't ring any bells for me. I have been going through parts of the batch code recently but it was always with a specific goal in mind. I still have to gain a more complete picture of it. I wasn't even aware that it has functionality built in to preserve memory.
Yeah, this issue is strange. It does not happen in the browser fortunately...
Here is the code https://github.com/drush-ops/drush/search?utf8=%E2%9C%93&q=Batch+process+has+consumed+in+excess+of+50%25&type=
Looks like the code is meant to stop the batch process if the memory limit is reached. I don't get though how it can have a memory limit. The whole concept of batch is meant to handle low memory and resource environments, and break a task to smaller pieces.
I think this feature should be removed from drush.
I've also run into this issue. It would be nice if drush could start a new process once it hits 50% memory usage.
I might have a solution for some of you.
One of my drush commands had the responsibility of looping over ~4k entities and loading 4 other associated entities for each main entity. I pared down my script until I figured out that I couldn't even load all that data without triggering this issue. Then I realized that there's probably a in-memory registry for entities pulled from the database. I found the \Drupal\Core\Entity\EntityStorageInterface::resetCache function which saved the day. Now, I reset the static cache when after every chunk of entities I pull from the database and I've had no memory problems since :)
Here's an example:
$this->entityTypeManager->getStorage($entityTypeId)->resetCache();
The problem is that resetCache() also resets the persistent cache.
See https://www.drupal.org/node/1199866 and https://www.drupal.org/node/2973262 for upcoming better solutions.
Maybe migrate has its own 50% check?
Migrate does have own check. Dont know who is at fault here.
Definately works in drush 9.6
I'm getting the same error message: Batch process has consumed in excess of 60% of available memory. Starting new thread.
This happens while I'm running a custom batch script that creates a lot of user accounts and profiles. Accounts are created one by one and not in bulk.
Any ideas on how to deal with this? Thanks!
In navneet's comment I see a workaround for the issue, but the issue still got closed. Am I missing something?
Edit: I am using drush 10.6.1 and I have this issue in a custom command.