Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions includes/batch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -195,14 +196,17 @@ function _drush_batch_command($id) {
if (_drush_batch_worker()) {
return _drush_batch_finished();
}
else {
return ['drush_batch_process_finished' => FALSE];
}
}


/**
* 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() {
Expand Down Expand Up @@ -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
Expand Down