Introduce Kernel#Barrier as a top level scheduling operation.#426
Introduce Kernel#Barrier as a top level scheduling operation.#426
Kernel#Barrier as a top level scheduling operation.#426Conversation
d96e74e to
49568f3
Compare
Async::Idler - Load-Based Admission ControlOverview
AlgorithmThe idler uses a proportional controller with memory to manage task admission: Key Components
Control Logicif load <= @maximum_load
# Underload: Allow task but prevent bursts
if @current > @backoff
# Preventive sleep using accumulated backoff
sleep(@current - @backoff)
# Gentle decay toward baseline
alpha = 0.99
@current *= alpha + (1.0 - alpha) * (load / @maximum_load)
end
# Proceed with task creation
else
# Overload: Increase backoff and sleep
@current *= (load / @maximum_load)
sleep(@current)
endDesign RationaleProblem: Burst After Load DropWhen load is high, Solution: Memory-Based Rate Limiting
This creates a soft ceiling that prevents bursts while maintaining good load tracking. Performance CharacteristicsBenchmarked with realistic workload (1000 tasks, each doing 10k microsleeps): Without Preventive Sleep
With Preventive Sleep (Current Implementation)
Key PropertiesSimplicity
Effectiveness
Predictability
Usageidler = Async::Idler.new(0.8) # 80% load threshold
# Schedule work when idle
idler.async do
# Your work here
endThe idler automatically:
Thread SafetyThe idler uses a Related
Benchmark code: require_relative "lib/async"
Barrier do |barrier|
1000.times.map do |i|
barrier.async do
puts "Starting #{i}: Load=#{Fiber.scheduler.load.round(3)}"
10000.times{sleep(0.000001)}
puts "Finished #{i}"
end
end
end |
|
|
Starting multiple concurrent tasks and waiting for them to finish is a common pattern. This change introduces a small ergonomic helper,
Barrier, defined inKernel, that encapsulates this behavior: it creates anAsync::Barrier, yields it to a block, waits for completion (usingSyncto run a reactor if needed), and ensures remaining tasks are stopped on exit.Types of Changes
Contribution