123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Testing::Parallelization::RoundRobinWorkStealingDistributor

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveSupport::Testing::Parallelization::RoundRobinDistributor
Defined in: activesupport/lib/active_support/testing/parallelization/test_distributor.rb

Overview

Round-robin distributor with work stealing enabled. Tests are initially assigned round-robin as they arrive (same as RoundRobinDistributor), but when a worker exhausts its queue, it can steal work from other workers to improve load balancing.

Constant Summary

RoundRobinDistributor - Inherited

WORK_WAIT_TIMEOUT

Class Method Summary

Instance Attribute Summary

RoundRobinDistributor - Inherited

TestDistributor - Inherited

#pending?

Check if there is pending work.

Instance Method Summary

RoundRobinDistributor - Inherited

#add_test, #close, #interrupt, #take, #exhausted?, #next_job, #pop_now,
#wait

Waits for work, rechecking exhausted? inside the mutex to handle the race where close() broadcasts before we start waiting.

TestDistributor - Inherited

#add_test

Add a test to be distributed to workers.

#close

Close the distributor.

#interrupt

Clear all pending work (called on interrupt).

#take

Retrieve the next test for a specific worker.

Constructor Details

This class inherits a constructor from ActiveSupport::Testing::Parallelization::RoundRobinDistributor

Instance Method Details

#exhausted?Boolean (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelization/test_distributor.rb', line 182

def exhausted?(...)
  @queues.all? { |q| q.closed? && q.empty? }
end

#next_job(worker_id) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelization/test_distributor.rb', line 166

def next_job(worker_id)
  pop_now(worker_id) || steal(worker_id)
end

#steal(worker_id) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelization/test_distributor.rb', line 170

def steal(worker_id)
  # Steal from other workers in a consistent order
  @worker_count.times do |offset|
    other_id = (worker_id + offset + 1) % @worker_count
    if job = pop_now(other_id)
      return job
    end
  end

  nil
end