drush icon indicating copy to clipboard operation
drush copied to clipboard

batch process fails to start new thread after reaching 50% of available memory

Open giorgio79 opened this issue 9 years ago • 15 comments

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

giorgio79 avatar Oct 29 '17 17:10 giorgio79

sounds like a bug ... what version of drush? please provide steps to reproduce, if possible.

weitzman avatar Oct 29 '17 19:10 weitzman

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.

giorgio79 avatar Oct 29 '17 19:10 giorgio79

Perhaps @pfrenssen has an idea about this as he recently touched the batch code..

weitzman avatar Feb 17 '18 15:02 weitzman

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.

pfrenssen avatar Feb 20 '18 15:02 pfrenssen

Yeah, this issue is strange. It does not happen in the browser fortunately...

giorgio79 avatar Feb 20 '18 18:02 giorgio79

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.

giorgio79 avatar Feb 21 '18 09:02 giorgio79

I think this feature should be removed from drush.

weitzman avatar Mar 04 '18 05:03 weitzman

I've also run into this issue. It would be nice if drush could start a new process once it hits 50% memory usage.

ryross avatar Jun 27 '18 19:06 ryross

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();

ryross avatar Jun 28 '18 00:06 ryross

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.

Berdir avatar Jun 28 '18 07:06 Berdir

Maybe migrate has its own 50% check?

weitzman avatar Dec 03 '18 14:12 weitzman

Migrate does have own check. Dont know who is at fault here.

weitzman avatar Mar 13 '19 12:03 weitzman

Definately works in drush 9.6

weitzman avatar Mar 30 '19 11:03 weitzman

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!

aramboyajyan avatar Jun 16 '19 14:06 aramboyajyan

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.

LedzZm avatar Nov 01 '21 13:11 LedzZm