1、详细内存模型
Managed Memory:
- Streaming jobs can use it for RocksDB state backend. (流处理中的RocksDB状态后端)
- Batch jobs can use it for sorting, hash tables, caching of intermediate results.(批处理排序、分区、中间结果缓存)
- Both streaming and batch jobs can use it for executing User Defined Functions in Python processes.(批流中Python的UDF函数)
各个用途的分配通过 taskmanager.memory.managed.consumer-weights
参数进行权重配置。
Network Memory:
- data record exchange between tasks(网络数据交换)
Framework Memory:
- You should not change the framework heap memory and framework off-heap memory without a good reason.(不建议修改默认值)。不计入slot资源中。
部署参数配置:
集群部署时,以上三个配置中必须要配置一个,否则启动会失败。
- 最简单的配置就是指定以下两个配置的一个
- If you have configured the task heap and managed memory explicitly, it is recommended to set neither total process memory nor total Flink memory. Otherwise, it may easily lead to memory configuration conflicts.(如果配置 task heap and managed memory这两个参数,就不要配置Total Memory,否则容易会造成冲突)
2、调优
2.1 Configure Total Memory
- standalone deployments:适合配置total Flink memory
- containers (Kubernetes, Yarn or Mesos):适合配置total process memory
2.2 Configure memory for state backends
只对TaskManagers有效
Heap state backend
- When running a stateless job or using a heap state backend (MemoryStateBackend or FsStateBackend), set managed memory to zero.(当不使用状态或者使用堆内状态后端时,设置manged memory为0)
RocksDB state backend
- The first step to try and increase performance should be to increase the amount of managed memory.(增加managed memory)
- The number of write buffers in RocksDB depends on the number of states you have in your application.(写缓冲取决于状态的数量)
- If your application has many states and you see frequent MemTable flushes (write-side bottleneck), but you cannot give more memory you can increase the ratio of memory going to the write buffers (
state.backend.rocksdb.memory.write-buffer-ratio
).(如果程序频繁刷写状态的话,调大刷写内存比例)
2.3 Configure memory for batch jobs
- Flink will attempt to allocate and use as much managed memory as configured for batch jobs but not go beyond its limits.(在不超过限制的情况下,尽可能多的分配manged memory)
2.4 Configure memory for sort-merge blocking shuffle
- The number of required network buffers per sort-merge blocking result partition is controlled by taskmanager.network.sort-shuffle.min-buffers and the default value is 64 which is quite small(网络缓冲的默认值是64,太小).you may also need to increase the size of total network memory by adjusting the config values of taskmanager.memory.network.fraction, taskmanager.memory.network.min and taskmanager. memory.network.max to avoid
insufficient number of network buffers
error.(通过配置网络内存的比例、最小值、最大值来提高网络内存总量的大小) - the sort-merge blocking shuffle implementation also uses some unmanaged direct memory for shuffle data writing and reading(排序合并的shuffle操作同样需要direct memory进行读写). you may need to reserve some direct memory for it by increasing the config value of taskmanager.memory.task .off-heap.size(通过增大对外内存的值来增加direct memory).
2.5 Local Execution
只有如下参数会生效