Package io.temporal.worker.tuning
Class FixedSizeSlotSupplier<SI extends SlotInfo>
- java.lang.Object
-
- io.temporal.worker.tuning.FixedSizeSlotSupplier<SI>
-
- Type Parameters:
SI- The slot info type for this supplier.
- All Implemented Interfaces:
SlotSupplier<SI>
public class FixedSizeSlotSupplier<SI extends SlotInfo> extends java.lang.Object implements SlotSupplier<SI>
This implementation ofSlotSupplierprovides a fixed number of slots backed by a semaphore, and is the default behavior when a custom supplier is not explicitly specified.
-
-
Constructor Summary
Constructors Constructor Description FixedSizeSlotSupplier(int numSlots)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaximumSlots()Because we currently use thread pools to execute tasks, there must be *some* defined upper-limit on the size of the thread pool for each kind of task.voidmarkSlotUsed(SlotMarkUsedContext<SI> ctx)This function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally.voidreleaseSlot(SlotReleaseContext<SI> ctx)This function is called once a permit is no longer needed.SlotPermitreserveSlot(SlotReserveContext<SI> ctx)This function is called before polling for new tasks.java.lang.StringtoString()java.util.Optional<SlotPermit>tryReserveSlot(SlotReserveContext<SI> ctx)This function is called when trying to reserve slots for "eager" workflow and activity tasks.
-
-
-
Method Detail
-
reserveSlot
public SlotPermit reserveSlot(SlotReserveContext<SI> ctx) throws java.lang.InterruptedException
Description copied from interface:SlotSupplierThis function is called before polling for new tasks. Your implementation should block until a slot is available, then return a permit to use that slot.- Specified by:
reserveSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for slot reservation.- Returns:
- A permit to use the slot which may be populated with your own data.
- Throws:
java.lang.InterruptedException- The worker may choose to interrupt the thread in order to cancel the reservation, or during shutdown. You may perform cleanup, and then should rethrow the exception.
-
tryReserveSlot
public java.util.Optional<SlotPermit> tryReserveSlot(SlotReserveContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called when trying to reserve slots for "eager" workflow and activity tasks. Eager tasks are those which are returned as a result of completing a workflow task, rather than from polling. Your implementation must not block, and If a slot is available, return a permit to use that slot.- Specified by:
tryReserveSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for slot reservation.- Returns:
- Maybe a permit to use the slot which may be populated with your own data.
-
markSlotUsed
public void markSlotUsed(SlotMarkUsedContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally. For example, if there is no work for a worker, a number of slots equal to the number of active pollers may already be reserved, but none of them are being used yet. This call should be non-blocking.- Specified by:
markSlotUsedin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for marking a slot as used.
-
releaseSlot
public void releaseSlot(SlotReleaseContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called once a permit is no longer needed. This could be because the task has finished, whether successfully or not, or because the slot was no longer needed (ex: the number of active pollers decreased). This call should be non-blocking.- Specified by:
releaseSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for releasing a slot.
-
getMaximumSlots
public int getMaximumSlots()
Description copied from interface:SlotSupplierBecause we currently use thread pools to execute tasks, there must be *some* defined upper-limit on the size of the thread pool for each kind of task. You must not hand out more permits than this number. If unspecified, the default isInteger.MAX_VALUE. Be aware that if your implementation hands out unreasonable numbers of permits, you could easily oversubscribe the worker, and cause it to run out of resources.This value should never change during the lifetime of the supplier.
- Specified by:
getMaximumSlotsin interfaceSlotSupplier<SI extends SlotInfo>- Returns:
- the maximum number of slots that can ever be in use at one type for this slot type.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-