diff --git a/includes/batch.inc b/includes/batch.inc index e2b927e121..5dc26a930e 100644 --- a/includes/batch.inc +++ b/includes/batch.inc @@ -52,12 +52,13 @@ class DrushBatchContext extends ArrayObject { * Process a Drupal batch by spawning multiple Drush processes. * * This function will include the correct batch engine for the current - * major version of Drupal, and will make use of the site-process - * library to spawn multiple worker threads to handle the processing of - * the current batch. + * major version of Drupal, and will make use of the drush_backend_invoke + * system to spawn multiple worker threads to handle the processing of + * the current batch, while keeping track of available memory. * * The batch system will process as many batch sets as possible until - * the entire batch has been completed. + * the entire batch has been completed or half of the available memory + * has been used. * * This function is a drop in replacement for the existing batch_process() * function of Drupal. @@ -195,6 +196,9 @@ function _drush_batch_command($id) { if (_drush_batch_worker()) { return _drush_batch_finished(); } + else { + return ['drush_batch_process_finished' => FALSE]; + } } @@ -202,7 +206,7 @@ function _drush_batch_command($id) { * Process batch operations * * Using the current $batch process each of the operations until the batch - * has been completed or half of the available memory for the process has been + * has been completed or 60% of the available memory for the process has been * reached. */ function _drush_batch_worker() { @@ -278,6 +282,15 @@ function _drush_batch_worker() { // At this point, either $current_set contains operations that need to be // processed or all sets have been completed. $queue = _batch_queue($current_set); + + // If we are in progressive mode, break processing after 60% of memory usage + // is reached. + if (drush_memory_limit() > 0 && (memory_get_usage() * 1.6) >= drush_memory_limit()) { + Drush::logger()->notice(dt("Batch process has consumed in excess of 50% of available memory. Starting new thread")); + // Record elapsed wall clock time. + $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2); + break; + } } // Reporting 100% progress will cause the whole batch to be considered