Big Data 6 min read

Understanding Flink Task Slots, Resource Allocation, and Slot Sharing Mechanisms

This article explains how Flink uses task slots to partition TaskManager resources, the benefits of slot sharing, the interaction between Scheduler, SlotPool, and ResourceManager, and the internal classes such as LogicalSlot, PhysicalSlot, and SlotSharingManager that enable resource isolation and sharing in stream processing jobs.

Architect
Architect
Architect
Understanding Flink Task Slots, Resource Allocation, and Slot Sharing Mechanisms

Task Slot

In Flink, each TaskManager runs as a JVM process and can host one or more subtasks; a task slot represents a subset of the TaskManager's resources, typically memory, allowing isolation of subtasks. Adjusting the number of slots per TaskManager controls the degree of isolation, with each slot sharing the same JVM when multiple slots are configured.

By default, Flink permits subtasks belonging to the same job to share a slot, which simplifies parallelism calculation and improves resource utilization, especially for lightweight map tasks.

Flink also provides APIs to control resource sharing, such as startNewChain, disableChaining, and slotSharingGroup, allowing users to avoid unintended sharing.

Resource Allocation Logic

The JobManager requests resources from the ResourceManager via the SlotProvider (Scheduler). The ResourceManager coordinates TaskManagers to satisfy these requests.

A detailed call flow diagram follows:

During execution, the SlotSharingManager decides whether multiple Executions can share the same slot, first checking the SlotPool for available resources before requesting new ones from the ResourceManager.

Scheduler

Requests slots from the SlotPool via allocateSlot.

Releases slots back to the SlotPool via returnLogicSlot.

SlotPool

Interaction with other components:

Scheduler → SlotPool: Scheduler requests resources.

SlotPool → ResourceManager: If SlotPool cannot satisfy the request, it asks the ResourceManager.

JobMaster → SlotPool: Resources obtained from TaskManagers are handed to SlotPool via JobMaster.

LogicalSlot

SingleLogicalSlot contains a SlotContext interface; PhysicalSlot extends SlotContext.

PhysicalSlot implements the Payload interface; PhysicalSlot.tryAssignPayload assigns a PhysicalSlot to a LogicalSlot.

PhysicalSlot

AllocatedSlot represents a resource segment allocated from a TaskExecutor.

Code example (illustrative) shows how a PhysicalSlot is assigned to a LogicalSlot.

Slot Resource Sharing

Flink supports two sharing mechanisms:

CoLocationGroup: Guarantees that the n‑th parallel instance of JobVertices in the same group run on the same slot.

SlotSharingGroup: Allows different JobVertices to share a slot with a looser constraint.

SlotSharingManager

Each sharing group is managed by a SlotSharingManager. For normal slot sharing, the manager looks up existing slots by JobVertex ID; for co‑location groups, it matches based on CoLocationConstraint.

Other Related Classes

CoLocationConstraint

SingleLogicalSlot

MultiTaskSlot

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Big DataFlinkResource Managementslot sharingTask Slot
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.