在Ubuntu上优化Kafka性能可从硬件、配置、网络等多方面入手,具体如下:
ulimit -n 65535
。net.core.somaxconn
、net.ipv4.tcp_max_syn_backlog
等提升网络吞吐。num.network.threads
和num.io.threads
:根据CPU核心数设置(通常为核数的2-3倍)。log.segment.bytes
:设置为1GB减少分段开销。log.retention.hours
:按需设置日志保留时间,避免磁盘占满。-Xms
和-Xmx
设置为相同值(如8GB),避免动态扩展开销。-XX:+UseG1GC
),减少GC停顿。compression.type=lz4
),合理设置batch.size
(如1MB)和linger.ms
(如100ms)。fetch.min.bytes
(如1MB)和fetch.max.wait.ms
(如1000ms)优化拉取效率。tcp_nodelay
、tcp_keepalive_time
)。注意:所有配置修改前需在测试环境验证,避免影响生产环境。
参考来源: