失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Flink 生产环境配置建议

Flink 生产环境配置建议

时间:2022-01-14 21:07:16

相关推荐

Flink 生产环境配置建议

flink-conf.yaml相关

-------------------------------------------------------------------------

checkpoint相关配置----------------------------

可以在代码里设置,但有的配置项如果都一致,不再想代码里设置,可以在这里配置默认值。

state.backend:状态存储后端,可配置值有'jobmanager', 'filesystem', 'rocksdb'等,在checkpoint数据存储在hdfs上时,配置该值为filesystem

state.checkpoints.dir:checkpoints写出的目录位置,比如:hdfs://ns/flink/flink-checkpoints

state.savepoints.dir:savepoints写出的目录位置,比如:hdfs://ns/flink/flink-checkpoints,一般与上面的值配置一致

execution.checkpointing.mode:检查点模式,默认值EXACTLY_ONCE,可选项AT_LEAST_ONCE

execution.checkpointing.interval:checkpoint的时间间隔,单位毫秒,比如5000

state.checkpoints.num-retained:checkpoint保留的个数,默认值1,不过建议比如设置为3,防止想要恢复更久前的状态,或者最近的一个checkpoint被误删除等情况。

execution.checkpointing.externalized-checkpoint-retention:该配置项定义了在任务取消(cancel,注意不是job failed是主动的cancel)时如何清理外部化的检查点。一般我们会配置为RETAIN_ON_CANCELLATION,即cancel时保留检查点。而DELETE_ON_CANCELLATION则表示cancel任务时删除检查点,只有在任务失败时,才会被保留。

execution.checkpointing.tolerable-failed-checkpoints:允许的连续checkpoint失败的次数,默认值是0,即只要出现checkpoint失败,作业就会失败,然后按照设置了的重启策略开始重启(setRestartStrategy),所以生产环境中一般设置2,即允许偶尔出现checkpoints失败的。

-------------------------------------------------------------------------

taskmanager.numberOfTaskSlots

每个taskmanager提供的插槽数目,默认值1。如果在standalone模式下,则我们一般一个机器界节点启动一个taskmanager,所以配置值一般略小于该机器的CPU数,而运行在yarn上,则要注意适当配置该值大小(相当于申请的vcore),假如只配置1,虽然task之间的隔离性很好(taskmanager挂掉了只影响自己),但是却不利于资源的利用率。太大则隔离性不好,taskmanager挂掉则所有运行在上面的task都将受影响。在yarn模式使用的时候会受到yarn.scheduler.maximum-allocation-vcores值的限制。在yarn模式,flink启动的task manager个数可以参照如下计算公式:num_of_manager = ceil(parallelism / slot) 即并行度除以slot个数,结果向上取整。

io.tmp.dirs

建议将其设置为不会自动定期清除的目录。

Flink 存放本地数据的目录,默认为系统临时目录(java.io.tmpdir 属性)。 如果配置了目录列表,Flink 将在目录之间轮换写文件。

默认情况下,放在这些目录中的数据包括 RocksDB 创建的文件、溢出的中间结果(批处理算法)和缓存的 jar 文件。

此数据不依赖于持久性/恢复,但如果此数据被删除,通常会导致重量级恢复操作。

默认情况下,Yarn 和 Kubernetes 设置会自动将此值配置成自己的本地工作目录。

standalone模式下jobmanager和taskmanager的pid存放位置

默认存放位置放在了/tmp下,会导致过一定时候后pids文件被删除而无法停止程序,所以建议修改存放位置,修改flink-conf.yaml里配置 env.pid.dir 修改为其他目录,一般比如$FLINK_HOME/pids

jobmanager.rpc.address

jobmanager的监听的rpc主机名。在standalone模式下需要配置

jobmanager.rpc.port

jobmanager的监听的rpc端口,默认值6123。在standalone模式下需要配置

JM内存相关-------------------------------

提交任务时一般只需要配置 jobmanager.memory.process.size,当默认的分配不符合你的需求时,可以再指定其他值。不过要注意的是假如还配置了其他内存值,那总的内存相加值不能大于 jobmanager.memory.process.size的值,不然会报错。

jobmanager.memory.process.size

jobmanager进程消耗的总内存大小,包含Total Flink Memory, JVM Metaspace, and JVM Overhead。在容器化的设置中,该值应该设置为容器内存大小,比如yarn的container内存大小。在standalone模式下,因为被所有任务共用,所以配置大点比如8g,16g。(Total Process Memory size for the JobManager. This includes all the memory that a JobManager JVM process consumes, consisting of Total Flink Memory, JVM Metaspace, and JVM Overhead. In containerized setups, this should be set to the container memory.)

jobmanager.memory.flink.size

jobmanager的总flink内存大小,包含JVM Heap Memory and Off-heap Memory,不包含JVM Metaspace and JVM Overhead。(Total Flink Memory size for the JobManager. This includes all the memory that a JobManager consumes, except for JVM Metaspace and JVM Overhead. It consists of JVM Heap Memory and Off-heap Memory.)

jobmanager.memory.heap.size

jobmanager进程的jvm heap大小。(JVM Heap Memory size for JobManager.)

jobmanager.memory.jvm-metaspace.size

jobmanager进程的jvmmetaspace大小。

jobmanager.memory.jvm-overhead.fraction

jobmanager进程的jvm overhead占用process.size的百分比。

(Fraction of Total Process Memory to be reserved for JVM Overhead. This is off-heap memory reserved for JVM overhead, such as thread stack space, compile cache, etc. This includes native memory but not direct memory, and will not be counted when Flink calculates JVM max direct memory size parameter. The size of JVM Overhead is derived to make up the configured fraction of the Total Process Memory. If the derived size is less or greater than the configured min or max size, the min or max size will be used. The exact size of JVM Overhead can be explicitly specified by setting the min and max size to the same value.)

jobmanager.memory.off-heap.size

jobmanager的off-heap内存大小。

(Off-heap Memory size for JobManager. This option covers all off-heap memory usage including direct and native memory allocation. The JVM direct memory limit of the JobManager process (-XX:MaxDirectMemorySize) will be set to this value if the limit is enabled by 'jobmanager.memory.enable-jvm-direct-memory-limit'.)

JM总体内存模型:

TM内存相关-------------------------------

和JM一样,单独配置某些内存项时,内存总和超过taskmanager.memory.process.size就会报错,特别注意下一般我们单独配置heap.size和process.size时,很容易报超内存错,因为有taskmanager.memory.managed.fraction的默认值是占process.size的0.4,所以很容易超了。

taskmanager.memory.process.size

taskmanager进程消耗的总内存大小,它包含Total Flink Memory, JVM Metaspace, and JVM Overhead。在容器化的设置中,该值应该设置为容器内存大小,比如yarn的container内存大小。

(Total Process Memory size for the TaskExecutors. This includes all the memory that a TaskExecutor consumes, consisting of Total Flink Memory, JVM Metaspace, and JVM Overhead. On containerized setups, this should be set to the container memory.

taskmanager.memory.task.heap.size

taskmanager进程的jvm heap大小。假如没设置的话,就是:

总内存大小 -Framework Heap Memory -Framework Off-Heap Memory -Task Off-Heap Memory -Managed Memory -Network Memory

(Task Heap Memory size for TaskExecutors. This is the size of JVM heap memory reserved for tasks. If not specified, it will be derived as Total Flink Memory minus Framework Heap Memory, Framework Off-Heap Memory, Task Off-Heap Memory, Managed Memory and Network Memory.)

taskmanager.memory.managed.size

taskmanager管理的堆外内存,由 MemoryManager 管理,用于中间结果缓存、排序、哈希表等,以及 RocksDB 状态后端。一般不指定由来taskmanager.memory.managed.fraction决定。(Managed Memory size for TaskExecutors. This is the size of off-heap memory managed by the memory manager, reserved for sorting, hash tables, caching of intermediate results and RocksDB state backend. Memory consumers can either allocate memory from the memory manager in the form of MemorySegments, or reserve bytes from the memory manager and keep their memory usage within that boundary. If unspecified, it will be derived to make up the configured fraction of the Total Flink Memory.)

taskmanager.memory.managed.fraction

taskmanager管理的堆外内存占总内存的百分比,默认值是0.4(Fraction of Total Flink Memory to be used as Managed Memory, if Managed Memory size is not explicitly specified.)

TM总体内存模型:

如果觉得《Flink 生产环境配置建议》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。