abstract class
Mosquito::ResourceGate
- Mosquito::ResourceGate
- Reference
- Object
Overview
A ResourceGate controls whether work should be dequeued based on external resource availability (GPU utilization, CPU load, network bandwidth, etc.).
Subclass ResourceGate and implement #check to test the resource.
The result is cached for #sample_ttl so expensive checks (shelling
out to nvidia-smi, reading /sys, etc.) aren't repeated on every
dequeue spin.
Example
class GpuUtilizationGate < Mosquito::ResourceGate
def initialize(@threshold : Float64 = 85.0)
super(sample_ttl: 2.seconds)
end
protected def check : Bool
current_gpu_utilization < @threshold
end
end
Direct Known Subclasses
Defined in:
mosquito/resource_gate.crConstructors
Instance Method Summary
-
#allow? : Bool
Returns the cached result of
#check, re-evaluating only after#sample_ttlhas elapsed since the last check. -
#released(job_run : JobRun, queue : Queue) : Nil
Called after a job finishes, in case the gate needs to update internal bookkeeping (e.g.
- #sample_ttl : Time::Span
Constructor Detail
Instance Method Detail
Returns the cached result of #check, re-evaluating only after
#sample_ttl has elapsed since the last check.
Called after a job finishes, in case the gate needs to update internal bookkeeping (e.g. decrement an in-flight counter).