Class: DispatchPolicy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch_policy/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dispatch_policy/config.rb', line 24

def initialize
  # Master switch. When false, the around_enqueue and the BulkEnqueue
  # patch pass through to the real adapter without staging — all of
  # the gem's machinery becomes a no-op for new perform_later calls.
  # The TickLoop also exits early. Used during cutovers to drain
  # the staging table without taking traffic offline.
  @enabled                   = true
  @tick_max_duration         = 25
  @partition_batch_size      = 50
  @admission_batch_size      = 100
  @idle_pause                = 0.5
  # Sleep between iterations when the previous tick admitted > 0
  # jobs. 0 (default) preserves the original "busy = no pause"
  # behavior. Set to a small value (e.g. 0.02) to back off the DB
  # when several TickLoops compete for connections; the per-loop
  # throughput ceiling becomes admission_batch_size / busy_pause.
  @busy_pause                = 0.0
  @partition_inactive_after  = 24 * 60 * 60
  @inflight_stale_after      = 5 * 60
  @inflight_heartbeat_interval = 30
  @real_adapter              = nil
  @logger                    = nil
  @clock                     = -> { Time.now.utc }
  @sweep_every_ticks         = 50
  @metrics_retention         = 24 * 60 * 60
  # AR role for the admission TX. nil = default connection. Set to
  # e.g. :queue when the host runs solid_queue on a separate DB.
  @database_role             = nil
  # Fairness: the half-life of decayed_admits (per-partition EWMA).
  # 60s means a partition's "recent activity" weight halves every
  # 60s of idleness. Tick reorders claimed partitions by lowest
  # decayed_admits first; under-admitted ones get first crack.
  @fairness_half_life_seconds = 60
  # Optional global cap on admissions per tick. nil = no cap; each
  # partition uses admission_batch_size as its ceiling. When set,
  # fair_share = ceil(cap / partitions_seen) is the per-partition
  # ceiling, with redistribution of leftover budget after pass-1.
  @tick_admission_budget     = nil
  # Operator-supplied "ceiling" of the underlying adapter, in jobs
  # per second. The dashboard renders the live admit rate as a
  # percentage of this and fires a hint when we're closing on it.
  # nil = no ceiling reference (just shows the absolute rate).
  # Measured locally against good_job: ~3500 jobs/sec per worker.
  @adapter_throughput_target = nil
end

Instance Attribute Details

#adapter_throughput_targetObject

Returns the value of attribute adapter_throughput_target.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def adapter_throughput_target
  @adapter_throughput_target
end

#admission_batch_sizeObject

Returns the value of attribute admission_batch_size.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def admission_batch_size
  @admission_batch_size
end

#busy_pauseObject

Returns the value of attribute busy_pause.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def busy_pause
  @busy_pause
end

#clockObject

Returns the value of attribute clock.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def clock
  @clock
end

#database_roleObject

Returns the value of attribute database_role.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def database_role
  @database_role
end

#enabledObject

Returns the value of attribute enabled.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def enabled
  @enabled
end

#fairness_half_life_secondsObject

Returns the value of attribute fairness_half_life_seconds.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def fairness_half_life_seconds
  @fairness_half_life_seconds
end

#idle_pauseObject

Returns the value of attribute idle_pause.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def idle_pause
  @idle_pause
end

#inflight_heartbeat_intervalObject

Returns the value of attribute inflight_heartbeat_interval.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def inflight_heartbeat_interval
  @inflight_heartbeat_interval
end

#inflight_stale_afterObject

Returns the value of attribute inflight_stale_after.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def inflight_stale_after
  @inflight_stale_after
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def logger
  @logger
end

#metrics_retentionObject

Returns the value of attribute metrics_retention.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def metrics_retention
  @metrics_retention
end

#partition_batch_sizeObject

Returns the value of attribute partition_batch_size.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def partition_batch_size
  @partition_batch_size
end

#partition_inactive_afterObject

Returns the value of attribute partition_inactive_after.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def partition_inactive_after
  @partition_inactive_after
end

#real_adapterObject

Returns the value of attribute real_adapter.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def real_adapter
  @real_adapter
end

#sweep_every_ticksObject

Returns the value of attribute sweep_every_ticks.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def sweep_every_ticks
  @sweep_every_ticks
end

#tick_admission_budgetObject

Returns the value of attribute tick_admission_budget.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def tick_admission_budget
  @tick_admission_budget
end

#tick_max_durationObject

Returns the value of attribute tick_max_duration.



5
6
7
# File 'lib/dispatch_policy/config.rb', line 5

def tick_max_duration
  @tick_max_duration
end

Instance Method Details

#nowObject



70
71
72
# File 'lib/dispatch_policy/config.rb', line 70

def now
  @clock.call
end