abstract class Mosquito::ResourceGate

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(sample_ttl : Time::Span = 2.seconds) #

Instance Method Detail

def allow? : Bool #

Returns the cached result of #check, re-evaluating only after #sample_ttl has elapsed since the last check.


def released(job_run : JobRun, queue : Queue) : Nil #

Called after a job finishes, in case the gate needs to update internal bookkeeping (e.g. decrement an in-flight counter).


def sample_ttl : Time::Span #