Detailed Memory Model

This section gives a detailed description of all components in Flink’s memory model of task executor.Check memory configuration guide for the basic memory setup.

Overview

Simple memory model

The following table lists all memory components, depicted above, and references Flink configuration optionswhich affect the size of the respective components:

Component Configuration options Description
Framework Heap Memorytaskmanager.memory.framework.heap.sizeJVM heap memory dedicated to Flink framework (advanced option)
Task Heap Memorytaskmanager.memory.task.heap.sizeJVM heap memory dedicated to Flink application to run operators and user code
Managed memorytaskmanager.memory.managed.sizetaskmanager.memory.managed.fractionNative memory managed by Flink, reserved for sorting, hash tables, caching of intermediate results and RocksDB state backend
Framework Off-heap Memorytaskmanager.memory.framework.off-heap.sizeOff-heap direct (or native) memory dedicated to Flink framework (advanced option)
Task Off-heap Memorytaskmanager.memory.task.off-heap.sizeOff-heap direct (or native) memory dedicated to Flink application to run operators
Network Memorytaskmanager.memory.network.mintaskmanager.memory.network.maxtaskmanager.memory.network.fractionDirect memory reserved for data record exchange between tasks (e.g. buffering for the transfer over the network), it is a capped fractionated component of the total Flink memory
JVM metaspacetaskmanager.memory.jvm-metaspace.sizeMetaspace size of the Flink JVM process
JVM Overheadtaskmanager.memory.jvm-overhead.mintaskmanager.memory.jvm-overhead.maxtaskmanager.memory.jvm-overhead.fractionNative memory reserved for other JVM overhead: e.g. thread stacks, code cache, garbage collection space etc, it is a capped fractionated component of the total process memory

As you can see, the size of some memory components can be simply set by the respective option.Other components can be tuned using multiple options.

Framework Memory

The framework heap memory and framework off-heap memory options are not supposed to be changed without a good reason.Adjust them only if you are sure that Flink needs more memory for some internal data structures or operations.It can be related to a particular deployment environment or job structure, like high parallelism.In addition, Flink dependencies, such as Hadoop may consume more direct or native memory in certain setups.

Note Neither heap nor off-heap versions of framework and task memory are currently isolated within Flink.The separation of framework and task memory can be used in future releases for further optimizations.

Capped Fractionated Components

This section describes the configuration details of the following options which can be a fraction of a certaintotal memory:

  • Network memory can be a fraction of the total Flink memory
  • JVM overhead can be a fraction of the total process memory

See also detailed memory model.

The size of those components always has to be between its maximum and minimum value, otherwise Flink startup will fail.The maximum and minimum values have defaults or can be explicitly set by corresponding configuration options.For example, if only the following memory options are set:

  • total Flink memory = 1000Mb,
  • network min = 64Mb,
  • network max = 128Mb,
  • network fraction = 0.1

then the network memory will be 1000Mb x 0.1 = 100Mb which is within the range 64-128Mb.

Notice if you configure the same maximum and minimum value it effectively means that its size is fixed to that value.

If the component memory is not explicitly configured, then Flink will use the fraction to calculate the memory sizebased on the total memory. The calculated value is capped by its corresponding min/max options.For example, if only the following memory options are set:

  • total Flink memory = 1000Mb,
  • network min = 128Mb,
  • network max = 256Mb,
  • network fraction = 0.1

then the network memory will be 128Mb because the size derived from fraction is 100Mb and it is less than the minimum.

It can also happen that the fraction is ignored if the sizes of the total memory and its other components are defined.In this case, the network memory is the rest of the total memory. The derived value still has to be within its min/maxrange otherwise the configuration fails. For example, suppose only the following memory options are set:

  • total Flink memory = 1000Mb,
  • task heap = 100Mb,
  • network min = 64Mb,
  • network max = 256Mb,
  • network fraction = 0.1

All other components of the total Flink memory have default values, including the default managed memory fraction.Then the network memory is not the fraction (1000Mb x 0.1 = 100Mb) but the rest of the total Flink memorywhich will either be within the range 64-256Mb or fail.

JVM Parameters

Flink explicitly adds the following memory related JVM arguments while starting the task executor process,based on the configured or derived memory component sizes:

JVM Arguments Value
-Xmx and -XmsFramework + Task Heap Memory
-XX:MaxDirectMemorySizeFramework + Task Off-Heap + Network Memory
-XX:MaxMetaspaceSizeJVM Metaspace

See also detailed memory model.

Local Execution

If you start Flink locally on your machine as a single java program without creating a cluster (e.g. from your IDE)then all components are ignored except for the following:

Memory component Relevant options Default value for the local execution
Task heaptaskmanager.memory.task.heap.sizeinfinite
Task off-heaptaskmanager.memory.task.off-heap.sizeinfinite
Managed memorytaskmanager.memory.managed.size128Mb
Network memorytaskmanager.memory.network.mintaskmanager.memory.network.max64Mb

All of the components listed above can be but do not have to be explicitly configured for the local execution.If they are not configured they are set to their default values. Task heap memory andtask off-heap memory are considered to be infinite (Long.MAX_VALUE bytes) and managed memoryhas a default value of 128Mb only for the local execution mode.

Note The task heap size is not related in any way to the real heap size in this case.It can become relevant for future optimizations coming with next releases. The actual JVM heap size of the startedlocal process is not controlled by Flink and depends on how you start the process.If you want to control the JVM heap size you have to explicitly pass the corresponding JVM arguments, e.g. -Xmx, -Xms.