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.

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.

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.

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:

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.

References