Class: Temporalio::Worker::Tuner
- Inherits:
-
Object
- Object
- Temporalio::Worker::Tuner
- Defined in:
- lib/temporalio/worker/tuner.rb
Overview
Worker tuner that allows for dynamic customization of some aspects of worker configuration.
Defined Under Namespace
Classes: SlotSupplier
Constant Summary collapse
- ResourceBasedTunerOptions =
Options for create_resource_based or SlotSupplier::ResourceBased.
Data.define( :target_memory_usage, :target_cpu_usage )
- ResourceBasedSlotOptions =
Options for a specific slot type being used with SlotSupplier::ResourceBased.
Data.define( :min_slots, :max_slots, :ramp_throttle )
Instance Attribute Summary collapse
-
#activity_slot_supplier ⇒ SlotSupplier
readonly
Slot supplier for activities.
-
#custom_slot_supplier_thread_pool ⇒ ThreadPool?
readonly
Thread pool for custom slot suppliers.
-
#local_activity_slot_supplier ⇒ SlotSupplier
readonly
Slot supplier for local activities.
-
#max_slots ⇒ Integer?
Maximum amount of slots permitted.
-
#min_slots ⇒ Integer?
Amount of slots that will be issued regardless of any other checks.
-
#ramp_throttle ⇒ Float?
Minimum time we will wait (after passing the minimum slots number) between handing out new slots in seconds.
-
#target_cpu_usage ⇒ Float
A value between 0 and 1 that represents the target (system) CPU usage.
-
#target_memory_usage ⇒ Float
A value between 0 and 1 that represents the target (system) memory usage.
-
#workflow_slot_supplier ⇒ SlotSupplier
readonly
Slot supplier for workflows.
Class Method Summary collapse
-
.create_fixed(workflow_slots: 100, activity_slots: 100, local_activity_slots: 100) ⇒ Tuner
Create a fixed-size tuner with the provided number of slots.
-
.create_resource_based(target_memory_usage:, target_cpu_usage:, workflow_options: ResourceBasedSlotOptions.new(min_slots: 5, max_slots: 500, ramp_throttle: 0.0), activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05), local_activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05)) ⇒ Tuner
Create a resource-based tuner with the provided options.
Instance Method Summary collapse
-
#initialize(workflow_slot_supplier:, activity_slot_supplier:, local_activity_slot_supplier:, custom_slot_supplier_thread_pool: ThreadPool.default) ⇒ Tuner
constructor
Create a tuner from 3 slot suppliers.
Constructor Details
#initialize(workflow_slot_supplier:, activity_slot_supplier:, local_activity_slot_supplier:, custom_slot_supplier_thread_pool: ThreadPool.default) ⇒ Tuner
Create a tuner from 3 slot suppliers.
336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/temporalio/worker/tuner.rb', line 336 def initialize( workflow_slot_supplier:, activity_slot_supplier:, local_activity_slot_supplier:, custom_slot_supplier_thread_pool: ThreadPool.default ) @workflow_slot_supplier = workflow_slot_supplier @activity_slot_supplier = activity_slot_supplier @local_activity_slot_supplier = local_activity_slot_supplier @custom_slot_supplier_thread_pool = custom_slot_supplier_thread_pool end |
Instance Attribute Details
#activity_slot_supplier ⇒ SlotSupplier (readonly)
Returns Slot supplier for activities.
319 320 321 |
# File 'lib/temporalio/worker/tuner.rb', line 319 def activity_slot_supplier @activity_slot_supplier end |
#custom_slot_supplier_thread_pool ⇒ ThreadPool? (readonly)
Returns Thread pool for custom slot suppliers.
325 326 327 |
# File 'lib/temporalio/worker/tuner.rb', line 325 def custom_slot_supplier_thread_pool @custom_slot_supplier_thread_pool end |
#local_activity_slot_supplier ⇒ SlotSupplier (readonly)
Returns Slot supplier for local activities.
322 323 324 |
# File 'lib/temporalio/worker/tuner.rb', line 322 def local_activity_slot_supplier @local_activity_slot_supplier end |
#max_slots ⇒ Integer?
Returns Maximum amount of slots permitted. Defaults to 500.
258 259 260 261 262 |
# File 'lib/temporalio/worker/tuner.rb', line 258 ResourceBasedSlotOptions = Data.define( :min_slots, :max_slots, :ramp_throttle ) |
#min_slots ⇒ Integer?
Returns Amount of slots that will be issued regardless of any other checks. Defaults to 5 for workflows and 1 for activities.
258 259 260 261 262 |
# File 'lib/temporalio/worker/tuner.rb', line 258 ResourceBasedSlotOptions = Data.define( :min_slots, :max_slots, :ramp_throttle ) |
#ramp_throttle ⇒ Float?
Returns Minimum time we will wait (after passing the minimum slots number) between handing out new slots in seconds. Defaults to 0 for workflows and 0.05 for activities.
This value matters because how many resources a task will use cannot be determined ahead of time, and thus the system should wait to see how much resources are used before issuing more slots.
258 259 260 261 262 |
# File 'lib/temporalio/worker/tuner.rb', line 258 ResourceBasedSlotOptions = Data.define( :min_slots, :max_slots, :ramp_throttle ) |
#target_cpu_usage ⇒ Float
Returns A value between 0 and 1 that represents the target (system) CPU usage. This can be set to 1.0 if desired, but it’s recommended to leave some headroom for other processes.
240 241 242 243 |
# File 'lib/temporalio/worker/tuner.rb', line 240 ResourceBasedTunerOptions = Data.define( :target_memory_usage, :target_cpu_usage ) |
#target_memory_usage ⇒ Float
Returns A value between 0 and 1 that represents the target (system) memory usage. It’s not recommended to set this higher than 0.8, since how much memory a workflow may use is not predictable, and you don’t want to encounter OOM errors.
240 241 242 243 |
# File 'lib/temporalio/worker/tuner.rb', line 240 ResourceBasedTunerOptions = Data.define( :target_memory_usage, :target_cpu_usage ) |
#workflow_slot_supplier ⇒ SlotSupplier (readonly)
Returns Slot supplier for workflows.
316 317 318 |
# File 'lib/temporalio/worker/tuner.rb', line 316 def workflow_slot_supplier @workflow_slot_supplier end |
Class Method Details
.create_fixed(workflow_slots: 100, activity_slots: 100, local_activity_slots: 100) ⇒ Tuner
Create a fixed-size tuner with the provided number of slots.
270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/temporalio/worker/tuner.rb', line 270 def self.create_fixed( workflow_slots: 100, activity_slots: 100, local_activity_slots: 100 ) new( workflow_slot_supplier: SlotSupplier::Fixed.new(workflow_slots), activity_slot_supplier: SlotSupplier::Fixed.new(activity_slots), local_activity_slot_supplier: SlotSupplier::Fixed.new(local_activity_slots) ) end |
.create_resource_based(target_memory_usage:, target_cpu_usage:, workflow_options: ResourceBasedSlotOptions.new(min_slots: 5, max_slots: 500, ramp_throttle: 0.0), activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05), local_activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05)) ⇒ Tuner
Create a resource-based tuner with the provided options.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/temporalio/worker/tuner.rb', line 294 def self.create_resource_based( target_memory_usage:, target_cpu_usage:, workflow_options: ResourceBasedSlotOptions.new(min_slots: 5, max_slots: 500, ramp_throttle: 0.0), activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05), local_activity_options: ResourceBasedSlotOptions.new(min_slots: 1, max_slots: 500, ramp_throttle: 0.05) ) = ResourceBasedTunerOptions.new(target_memory_usage:, target_cpu_usage:) new( workflow_slot_supplier: SlotSupplier::ResourceBased.new( tuner_options:, slot_options: ), activity_slot_supplier: SlotSupplier::ResourceBased.new( tuner_options:, slot_options: ), local_activity_slot_supplier: SlotSupplier::ResourceBased.new( tuner_options:, slot_options: ) ) end |