Class: Temporalio::Worker::Tuner

Inherits:
Object
  • Object
show all
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: ResourceBasedSlotOptions, ResourceBasedTunerOptions, SlotSupplier

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



332
333
334
335
336
337
338
339
340
341
342
# File 'lib/temporalio/worker/tuner.rb', line 332

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_supplierSlotSupplier (readonly)



315
316
317
# File 'lib/temporalio/worker/tuner.rb', line 315

def activity_slot_supplier
  @activity_slot_supplier
end

#custom_slot_supplier_thread_poolThreadPool? (readonly)



321
322
323
# File 'lib/temporalio/worker/tuner.rb', line 321

def custom_slot_supplier_thread_pool
  @custom_slot_supplier_thread_pool
end

#local_activity_slot_supplierSlotSupplier (readonly)



318
319
320
# File 'lib/temporalio/worker/tuner.rb', line 318

def local_activity_slot_supplier
  @local_activity_slot_supplier
end

#max_slotsInteger?



254
255
256
257
258
# File 'lib/temporalio/worker/tuner.rb', line 254

ResourceBasedSlotOptions = Data.define(
  :min_slots,
  :max_slots,
  :ramp_throttle
)

#min_slotsInteger?



254
255
256
257
258
# File 'lib/temporalio/worker/tuner.rb', line 254

ResourceBasedSlotOptions = Data.define(
  :min_slots,
  :max_slots,
  :ramp_throttle
)

#ramp_throttleFloat?



254
255
256
257
258
# File 'lib/temporalio/worker/tuner.rb', line 254

ResourceBasedSlotOptions = Data.define(
  :min_slots,
  :max_slots,
  :ramp_throttle
)

#target_cpu_usageFloat



236
237
238
239
# File 'lib/temporalio/worker/tuner.rb', line 236

ResourceBasedTunerOptions = Data.define(
  :target_memory_usage,
  :target_cpu_usage
)

#target_memory_usageFloat



236
237
238
239
# File 'lib/temporalio/worker/tuner.rb', line 236

ResourceBasedTunerOptions = Data.define(
  :target_memory_usage,
  :target_cpu_usage
)

#workflow_slot_supplierSlotSupplier (readonly)



312
313
314
# File 'lib/temporalio/worker/tuner.rb', line 312

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.



266
267
268
269
270
271
272
273
274
275
276
# File 'lib/temporalio/worker/tuner.rb', line 266

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.



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/temporalio/worker/tuner.rb', line 290

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)
)
  tuner_options = ResourceBasedTunerOptions.new(target_memory_usage:, target_cpu_usage:)
  new(
    workflow_slot_supplier: SlotSupplier::ResourceBased.new(
      tuner_options:, slot_options: workflow_options
    ),
    activity_slot_supplier: SlotSupplier::ResourceBased.new(
      tuner_options:, slot_options: activity_options
    ),
    local_activity_slot_supplier: SlotSupplier::ResourceBased.new(
      tuner_options:, slot_options: local_activity_options
    )
  )
end