问题描述
flink默认分配的内存,不合理,jvm 堆内存太小,其他内存太大。向yarn申请8G内存,最后分配到heap的大小才3.2G,不是让人抓狂吗?
以上是,向yarn申请8G内存,实时分配的内存是上图所示。
内存分析:
1.内存分配中,TaskHeap占用89%,其实这时已经fullGC,
2.但ManagedMemory分配是2.78G,实际用1M都没有。
3. network内存分配了712M,实际才使用1.8M。
希望把 ManagerdMemory和Network的内存分配给TaskMemory,如何才能做到?
taskmanager.memory.managed.fraction
源码中找:
public static final ConfigOption<Float> MANAGED_MEMORY_FRACTION =
key("taskmanager.memory.managed.fraction")
.floatType()
.defaultValue(0.4f)
.withDescription(
"Fraction of Total Flink Memory to be used as Managed Memory, if Managed Memory size is not"
+ " explicitly specified.");
默认值是0.4.
public static final ConfigOption<Float> NETWORK_MEMORY_FRACTION =
key("taskmanager.memory.network.fraction")
.floatType()
.defaultValue(0.1f)
.withDeprecatedKeys(
NettyShuffleEnvironmentOptions.NETWORK_BUFFERS_MEMORY_FRACTION.key())
.withDescription(
"Fraction of Total Flink Memory to be used as Network Memory. Network Memory is off-heap"
+ " memory reserved for ShuffleEnvironment (e.g., network buffers). Network Memory size is derived to"
+ " make up the configured fraction of the Total Flink Memory. If the derived size is less/greater than"
+ " the configured min/max size, the min/max size will be used. The exact size of Network Memory can be"
+ " explicitly specified by setting the min/max size to the same value.");
默认值:
taskmanager.memory.network.fraction = 0.1
把这两个默认值,配置文件是: flink-conf.yaml 改为
taskmanager.memory.managed.fraction: 0.1
taskmanager.memory.network.fraction : 0.05
重启服务
发现,修改的内存,ManagedMemory, NetworkMemory变小了,Task内存变大了。
看来task内存数,其他固定值分配完成后,剩下作为堆内存。
这两个值,看上去可以继续调小的。 taskmanager.memory.managed.fraction: 0.05都完全够用。
问题解决,开心。
默认值为什么是这么大?是什么应用场景呢? 起码我的应用场景用不了这种默认值。 碰到了再说。。。