过于频繁地滚动重新分区主题的日志会导致机器内存不足 运行 kafka
Too frequently rolling logs for repartition topic results in out of memory in machine running kafka
重新分区主题滚动日志的速度过快,我们非常确定他会导致机器 运行 内存不足。当我们重新处理包含大量消息的主题时,当我们更新了 streams-app 的某些部分使其需要重新处理时,就会发生这种情况。输入主题包含时间戳长达两年的消息。
这适用于旧版本的流 (1.0.1),但是重新分区主题不会足够快地清理。
主题设置:
kafka-topics.sh --topic my_state_store-repartition --describe
Topic:my_state_store-repartition PartitionCount:1 ReplicationFactor:1 Configs:segment.bytes=52428800,retention.ms=9223372036854775807,segment.index.bytes=52428800,cleanup.policy=delete,segment.ms=600000
Topic: my_state_store-repartition Partition: 0 Leader: 1001 Replicas: 1001 Isr: 1001
卡夫卡日志 |尾巴:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000100560000, 131072, 0) failed; error='Out of memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 131072 bytes for committing reserved memory.
# An error report file with more information is saved as:
# //hs_err_pid1.log
其中一个状态存储 repartion 日志文件夹。
ubuntu@ip-172-31-20-159:~$ sudo ls -l -h /var/lib/docker/volumes/<volumeId>/_data/kafka-logs/my_state_store-repartition-0 |tail -n100
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873778.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873778.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873778.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873788.index
-rw-r--r-- 1 root root 46K Oct 9 13:43 00000000000011873788.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873788.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873788.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873814.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873814.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873814.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873814.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873821.index
-rw-r--r-- 1 root root 45K Oct 9 13:43 00000000000011873821.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873821.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873821.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873846.index
-rw-r--r-- 1 root root 46K Oct 9 13:43 00000000000011873846.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873846.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873846.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873873.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873873.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873873.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873873.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873881.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873881.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873881.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873881.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873890.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873890.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873890.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873890.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873899.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873899.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873899.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873899.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873908.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873908.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873908.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873908.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873917.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873917.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873917.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873917.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873927.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873927.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873927.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873927.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011873937.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011873937.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873937.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873937.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873957.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873957.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873957.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873957.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873967.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873967.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873967.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873967.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873977.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873977.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873977.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873977.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873987.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873987.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873987.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873987.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011873997.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011873997.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873997.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873997.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874016.index
-rw-r--r-- 1 root root 32K Oct 9 13:43 00000000000011874016.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874016.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874016.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874034.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011874034.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874034.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874034.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874052.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011874052.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874052.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874052.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874061.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011874061.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874061.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874061.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874070.index
-rw-r--r-- 1 root root 30K Oct 9 13:43 00000000000011874070.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874070.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874070.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874086.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011874086.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874086.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874086.timeindex
-rw-r--r-- 1 root root 50M Oct 9 13:43 00000000000011874095.index
-rw-r--r-- 1 root root 265K Oct 9 13:43 00000000000011874095.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874095.snapshot
-rw-r--r-- 1 root root 50M Oct 9 13:43 00000000000011874095.timeindex
-rw-r--r-- 1 root root 14 Oct 9 13:42 leader-epoch-checkpoint
问题与 "segment.ms=600000" 设置有关。这是基于时间戳,而不是墙时间。把segment.ms改成Long.max()就解决了,然后segment有50mb才roll。那么问题就变成了如何更改重新分区主题的设置。可以使用 kafka-topic.sh 手动完成,但这对于很多不同的应用程序来说是不可持续的,并且当我们改变它聚合的方式时需要重置它们。据我了解,我无法使用 kafka-streams 更改重新分区主题的设置?甚至更好的是段滚动以防止或类似的某种最短时间?
EDIT1: 好像我理解错了segment.ms,它是段内时间戳之间的最大差异。(?)设置它long.max有点不必要,设置它就解决了我们的问题到 30 天,并且应该也适用于更短的段大小。
这是 2.0 版的问题,重新分区主题的标准设置已设置 segment.ms。当您重新处理旧消息时,这会导致即时滚动。在较新的版本中,此配置未设置,这解决了我们的问题。
Ps。感谢@Mathias J. Sax 的评论!
重新分区主题滚动日志的速度过快,我们非常确定他会导致机器 运行 内存不足。当我们重新处理包含大量消息的主题时,当我们更新了 streams-app 的某些部分使其需要重新处理时,就会发生这种情况。输入主题包含时间戳长达两年的消息。
这适用于旧版本的流 (1.0.1),但是重新分区主题不会足够快地清理。
主题设置:
kafka-topics.sh --topic my_state_store-repartition --describe
Topic:my_state_store-repartition PartitionCount:1 ReplicationFactor:1 Configs:segment.bytes=52428800,retention.ms=9223372036854775807,segment.index.bytes=52428800,cleanup.policy=delete,segment.ms=600000
Topic: my_state_store-repartition Partition: 0 Leader: 1001 Replicas: 1001 Isr: 1001
卡夫卡日志 |尾巴:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000100560000, 131072, 0) failed; error='Out of memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 131072 bytes for committing reserved memory.
# An error report file with more information is saved as:
# //hs_err_pid1.log
其中一个状态存储 repartion 日志文件夹。
ubuntu@ip-172-31-20-159:~$ sudo ls -l -h /var/lib/docker/volumes/<volumeId>/_data/kafka-logs/my_state_store-repartition-0 |tail -n100
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873778.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873778.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873778.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873788.index
-rw-r--r-- 1 root root 46K Oct 9 13:43 00000000000011873788.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873788.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873788.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873814.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873814.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873814.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873814.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873821.index
-rw-r--r-- 1 root root 45K Oct 9 13:43 00000000000011873821.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873821.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873821.timeindex
-rw-r--r-- 1 root root 16 Oct 9 13:43 00000000000011873846.index
-rw-r--r-- 1 root root 46K Oct 9 13:43 00000000000011873846.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873846.snapshot
-rw-r--r-- 1 root root 24 Oct 9 13:43 00000000000011873846.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873873.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873873.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873873.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873873.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873881.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873881.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873881.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873881.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873890.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873890.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873890.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873890.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873899.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873899.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873899.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873899.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873908.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873908.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873908.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873908.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873917.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873917.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873917.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873917.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873927.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873927.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873927.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873927.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011873937.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011873937.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873937.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873937.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873957.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873957.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873957.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873957.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873967.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011873967.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873967.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873967.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873977.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873977.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873977.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873977.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011873987.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011873987.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873987.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873987.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011873997.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011873997.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011873997.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011873997.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874016.index
-rw-r--r-- 1 root root 32K Oct 9 13:43 00000000000011874016.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874016.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874016.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874034.index
-rw-r--r-- 1 root root 31K Oct 9 13:43 00000000000011874034.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874034.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874034.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874052.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011874052.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874052.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874052.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874061.index
-rw-r--r-- 1 root root 15K Oct 9 13:43 00000000000011874061.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874061.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874061.timeindex
-rw-r--r-- 1 root root 8 Oct 9 13:43 00000000000011874070.index
-rw-r--r-- 1 root root 30K Oct 9 13:43 00000000000011874070.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874070.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874070.timeindex
-rw-r--r-- 1 root root 0 Oct 9 13:43 00000000000011874086.index
-rw-r--r-- 1 root root 16K Oct 9 13:43 00000000000011874086.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874086.snapshot
-rw-r--r-- 1 root root 12 Oct 9 13:43 00000000000011874086.timeindex
-rw-r--r-- 1 root root 50M Oct 9 13:43 00000000000011874095.index
-rw-r--r-- 1 root root 265K Oct 9 13:43 00000000000011874095.log
-rw-r--r-- 1 root root 10 Oct 9 13:43 00000000000011874095.snapshot
-rw-r--r-- 1 root root 50M Oct 9 13:43 00000000000011874095.timeindex
-rw-r--r-- 1 root root 14 Oct 9 13:42 leader-epoch-checkpoint
问题与 "segment.ms=600000" 设置有关。这是基于时间戳,而不是墙时间。把segment.ms改成Long.max()就解决了,然后segment有50mb才roll。那么问题就变成了如何更改重新分区主题的设置。可以使用 kafka-topic.sh 手动完成,但这对于很多不同的应用程序来说是不可持续的,并且当我们改变它聚合的方式时需要重置它们。据我了解,我无法使用 kafka-streams 更改重新分区主题的设置?甚至更好的是段滚动以防止或类似的某种最短时间?
EDIT1: 好像我理解错了segment.ms,它是段内时间戳之间的最大差异。(?)设置它long.max有点不必要,设置它就解决了我们的问题到 30 天,并且应该也适用于更短的段大小。
这是 2.0 版的问题,重新分区主题的标准设置已设置 segment.ms。当您重新处理旧消息时,这会导致即时滚动。在较新的版本中,此配置未设置,这解决了我们的问题。
Ps。感谢@Mathias J. Sax 的评论!