Flink TaskManagers, Task Slots, Subtasks, and Parallelism
A Flink job describes what to process. Parallelism determines how many instances do the processing. TaskManagers provide the worker processes, and task slots provide the scheduling capacity.
The confusing part is that these are not one-to-one relationships: a slot is not a CPU core, a slot can contain multiple tasks, and one task can contain multiple chained operators.
This guide builds one example from the logical pipeline down to the worker processes. On narrow screens, scroll the diagrams horizontally to keep their labels readable.
1. The Vocabulary Before the Diagrams
| Term | What it means | Example |
|---|---|---|
| JobManager | Coordinates job execution, scheduling, checkpoints, and recovery. | Decides where execution attempts should run. |
| TaskManager | A worker JVM that executes tasks and exchanges data. | Two worker processes in a cluster. |
| Task slot | A resource-allocation unit offered by a TaskManager. | Each worker offers two slots. |
| Operator | A logical processing step in the pipeline. | Source, Map, or Sink. |
| Operator subtask | One parallel instance of an operator. | Map subtask 0 through Map subtask 3. |
| Task | An executable unit that can contain a chain of operator subtasks. | Source 0 and Map 0 execute together. |
| Parallelism | The number of parallel instances of an operator or task vertex. | Map parallelism of 4 means four Map instances. |
Flink’s UI and documentation sometimes use subtask for a parallel instance of an executable, possibly chained, task vertex. Here, operator subtask means an individual logical operator instance; task means the runtime execution unit after chaining.
2. TaskManagers Supply Slots
Consider a cluster with:
- 2 TaskManagers, each running in its own JVM.
- 2 task slots per TaskManager.
- 4 total physical slots available before other jobs consume them.
%%{init: {"flowchart": {"useMaxWidth": false}}}%%
flowchart TB
JM["JobManager<br/>Scheduling and recovery"]
subgraph WA["Worker A"]
direction TB
TMA["TaskManager A<br/>One JVM process"]
A0["Physical slot A0"]
A1["Physical slot A1"]
TMA --> A0
TMA --> A1
end
subgraph WB["Worker B"]
direction TB
TMB["TaskManager B<br/>One JVM process"]
B0["Physical slot B0"]
B1["Physical slot B1"]
TMB --> B0
TMB --> B1
end
JM -.-> TMA
JM -.-> TMB
classDef coordinator fill:#0f172a,stroke:#0f172a,color:#ffffff
classDef worker fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
classDef slot fill:#e0f2fe,stroke:#0284c7,color:#0c4a6e
class JM coordinator
class TMA,TMB worker
class A0,A1,B0,B1 slot
style WA fill:#f8fafc,stroke:#cbd5e1
style WB fill:#f8fafc,stroke:#cbd5e1
Diagram 1: Resource hierarchy, not record flow. The JobManager coordinates work; the TaskManagers execute it.
The worker setting is:
taskmanager.numberOfTaskSlots: 2
For this cluster:
Total physical slots = TaskManagers x slots per TaskManager
= 2 x 2
= 4
A slot represents a share of worker resources. For example, under the standard slot model, two slots divide a TaskManager’s managed-memory budget into two shares.
Slots do not provide CPU-core isolation. Two slots do not necessarily mean two dedicated CPU cores, and increasing the slot count does not create more CPU or memory.
3. Parallelism Expands Operators into Subtasks
Our example pipeline is:
Source: parallelism 4
|
Map: parallelism 4
|
Rebalance
|
Sink: parallelism 2
Each operator has its own parallelism. A default parallelism can be set on the execution environment, and individual operators can override it.
Assume sourceStream is a parallel source configured with parallelism 4, and sink is the application’s sink connector:
env.setParallelism(4);
DataStream<String> mapped = sourceStream
.map(String::trim)
.name("Map")
.setParallelism(4);
mapped
.rebalance()
.sinkTo(sink)
.name("Sink")
.setParallelism(2);
The explicit rebalance() makes the redistribution in the next diagram clear. Each Map instance can send records to either Sink instance.
%%{init: {"flowchart": {"useMaxWidth": false}}}%%
flowchart LR
subgraph SOURCES["Source: parallelism 4"]
direction TB
S0["Source 0"]
S1["Source 1"]
S2["Source 2"]
S3["Source 3"]
end
subgraph MAPS["Map: parallelism 4"]
direction TB
M0["Map 0"]
M1["Map 1"]
M2["Map 2"]
M3["Map 3"]
end
R["Rebalance exchange<br/>Record redistribution<br/>Not an operator subtask"]
subgraph SINKS["Sink: parallelism 2"]
direction TB
K0["Sink 0"]
K1["Sink 1"]
end
S0 --> M0
S1 --> M1
S2 --> M2
S3 --> M3
M0 --> R
M1 --> R
M2 --> R
M3 --> R
R --> K0
R --> K1
classDef source fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
classDef map fill:#ccfbf1,stroke:#0d9488,color:#134e4a
classDef sink fill:#ffedd5,stroke:#ea580c,color:#7c2d12
classDef exchange fill:#f1f5f9,stroke:#64748b,color:#334155
class S0,S1,S2,S3 source
class M0,M1,M2,M3 map
class K0,K1 sink
class R exchange
style SOURCES fill:#f8fafc,stroke:#cbd5e1
style MAPS fill:#f8fafc,stroke:#cbd5e1
style SINKS fill:#f8fafc,stroke:#cbd5e1
Diagram 2: Ten logical operator subtasks: four Sources, four Maps, and two Sinks. The gray exchange box represents routing, not an additional operator or task. This is not a slot-allocation diagram.
Different subtasks process different portions of the input. With rebalance(), records are distributed across downstream instances; with keyBy(), records with the same key are routed to the same downstream keyed subtask.
Higher parallelism does not guarantee evenly distributed work. A hot key, limited source partitions, or a slow sink can still create a bottleneck.
4. Operator Chaining Changes the Number of Runtime Tasks
If Source and Map support chaining, have compatible settings, and are connected by a forward edge at the same parallelism, Flink can combine each Source/Map pair into one task.
%%{init: {"flowchart": {"useMaxWidth": false}}}%%
flowchart TB
subgraph SEPARATE["Without chaining: two tasks"]
direction LR
US["Source 0<br/>Task execution thread A"]
UM["Map 0<br/>Task execution thread B"]
US -->|"Task boundary"| UM
end
subgraph CHAINED["With chaining: one task and one execution thread"]
direction LR
CS["Source 0"]
CM["Map 0"]
CS -->|"Within the same task"| CM
end
classDef source fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
classDef map fill:#ccfbf1,stroke:#0d9488,color:#134e4a
class US,CS source
class UM,CM map
style SEPARATE fill:#f8fafc,stroke:#cbd5e1
style CHAINED fill:#f0fdfa,stroke:#0d9488
Diagram 3: Chaining avoids a task-to-task handoff. It does not merge multiple parallel instances of the same operator.
The same pattern can apply to indices 1, 2, and 3. Our example then has:
| Quantity | Count |
|---|---|
| Logical Source operator subtasks | 4 |
| Logical Map operator subtasks | 4 |
| Logical Sink operator subtasks | 2 |
| Chained Source/Map runtime tasks | 4 |
| Separate Sink runtime tasks | 2 |
| Total runtime tasks after chaining | 6 |
Each task has its own main execution thread. A worker also has network, checkpointing, connector, and other background threads; six tasks does not mean the whole cluster has only six JVM threads.
The rebalance boundary and different downstream parallelism prevent the Sink from joining these Source/Map chains. Actual chains depend on operator and connector compatibility, not just matching parallelism.
For clarity, this example assumes the sink does not introduce additional execution stages. Real connectors can add writers, committers, or other vertices that must be included when examining the actual job graph.
5. Slot Sharing Lets Multiple Tasks Use a Physical Slot
Chaining and slot sharing solve different problems:
| Mechanism | What is shared? | Do the operators run in one task? |
|---|---|---|
| Operator chaining | A task execution thread and in-task processing path. | Yes, for that chain. |
| Slot sharing | A physical slot’s allocated resources. | Not necessarily; separate tasks retain separate execution threads. |
With the default slot-sharing group, tasks from different vertices of the same job can share physical slots. One possible placement of our six runtime tasks is:
%%{init: {"flowchart": {"useMaxWidth": false}}}%%
flowchart TB
subgraph WORKER_A["TaskManager A: one JVM"]
direction LR
subgraph SLOT_A0["Physical slot A0"]
direction TB
C0["Source 0 + Map 0<br/>One chained task / thread"]
SK0["Sink 0<br/>A separate task / thread"]
C0 ~~~ SK0
end
subgraph SLOT_A1["Physical slot A1"]
C1["Source 1 + Map 1<br/>One chained task / thread"]
end
end
subgraph WORKER_B["TaskManager B: one JVM"]
direction LR
subgraph SLOT_B0["Physical slot B0"]
direction TB
C2["Source 2 + Map 2<br/>One chained task / thread"]
SK1["Sink 1<br/>A separate task / thread"]
C2 ~~~ SK1
end
subgraph SLOT_B1["Physical slot B1"]
C3["Source 3 + Map 3<br/>One chained task / thread"]
end
end
classDef chain fill:#ccfbf1,stroke:#0d9488,color:#134e4a
classDef sink fill:#ffedd5,stroke:#ea580c,color:#7c2d12
class C0,C1,C2,C3 chain
class SK0,SK1 sink
style WORKER_A fill:#f8fafc,stroke:#94a3b8
style WORKER_B fill:#f8fafc,stroke:#94a3b8
style SLOT_A0 fill:#eff6ff,stroke:#2563eb
style SLOT_A1 fill:#eff6ff,stroke:#2563eb
style SLOT_B0 fill:#eff6ff,stroke:#2563eb
style SLOT_B1 fill:#eff6ff,stroke:#2563eb
Diagram 4: Placement only, not record routing. The scheduler may choose a different arrangement; this is not a guarantee of exact slot or worker assignments.
Slots A0 and B0 each host a chained Source/Map task and a separate Sink task. Those two tasks share the slot’s resources, not a single task execution thread.
The important result:
10 logical operator subtasks
6 runtime tasks after chaining
4 physical slots with default slot sharing
2 TaskManager JVM processes
Without Source/Map chaining, this example could have ten runtime tasks while still fitting into four physical slots through slot sharing.
6. How Many Slots Does the Job Need?
For the usual coarse-grained, concurrently running streaming graph with one default slot-sharing group:
Required physical slots = highest task-vertex parallelism in the group
= max(4, 4, 2)
= 4
It is not 4 + 4 + 2 = 10.
If the Source/Map tasks use one slot-sharing group and the Sink uses another, the groups cannot share physical slots with each other:
Source/Map group: 4 slots
Sink group: 2 slots
Total: 6 slots
These are scheduling rules for the stated example, not a universal capacity formula for every Flink workload. Batch execution, adaptive scheduling, resource profiles, connector-added vertices, and other jobs consuming slots can change the situation.
What If Parallelism Is Increased to Six?
For a fixed-parallelism streaming graph whose highest parallelism becomes 6, four available slots are insufficient under these assumptions. Flink needs suitable additional capacity, or scheduling can wait and eventually fail according to its allocation settings.
Possible capacity changes include adding a third two-slot TaskManager or changing worker sizing and slot configuration. Adaptive scheduling may adjust parallelism instead, when the deployment and job are configured to support it.
Simply increasing slots per worker is not free scaling. It changes how the same worker resources are shared. Check CPU capacity, managed memory, state size, network memory, and external-system throughput before doing so.
7. Isolation and Failure: The JVM Boundary Matters
Tasks in different slots on one TaskManager still share a process. Slots do not isolate them from a fatal JVM error or a container-level out-of-memory kill.
If TaskManager A in Diagram 4 disappears, both of its slots disappear with it, affecting every task placed there. Tasks must recover on healthy workers, subject to the job’s failover and restart strategies.
By contrast, an ordinary task exception can leave the TaskManager JVM alive. Recovery can reuse available capacity without necessarily creating another worker.
The distinction is explained in more detail in Why Flink Jobs Restart: Checkpoint Failures and Recovery.
A Quick Mental Model
- TaskManager: The worker process.
- Slot: A schedulable share of that worker’s resources, not a CPU core.
- Operator subtask: One parallel instance of a logical processing step.
- Task: The execution unit after compatible operator subtasks are chained.
- Parallelism: How many parallel instances a processing vertex runs.
- Slot sharing: Different task vertices of the same job can use the same physical slot.
When a job looks larger than its slot count, count the parallel task vertices and slot-sharing groups, not just the number of boxes in the logical pipeline.