今天我们来看看为优化logstash而做的一些测试和配置。
一、监控
要优化一个组件,必须了解这个组件在不同压力下的资源占用情况吧。当然作为一个java应用,我们主要关注logstash的jvm的使用情况,方法如下:
GET localhost:9600/_node/jvm?pretty
GET localhost:9600/_node/stats/jvm?pretty
二、指标
我以每秒转发的消息数作为性能指标(每个消息数量1024字节)
三、jvm配置
离开jvm配置去讨论性能就是耍流氓。有多少钱办多大的事,有多大的实力娶多漂亮的女人,这都是真理。
把jvm配置从:
-Xms1g
-Xmx1g
增长为
-Xms1536m
-Xmx1536m
性能增长效果不明显,但是可以减少发送错误!
四、配置文件优化
1、pipeline.workers: 2
The number of workers that will, in parallel, execute the filter and output stages of the pipeline.
filter和output的并行线程数量。
2改为4, [有效果,性能提升10%左右]
备注:
logstash的整个过程是intput-> filter -> output
pipeline.workers会加快filter和output的处理进程,从而提高整体的处理速度。
2、pipeline.batch.size: 125
The maximum number of events an individual worker thread will collect from inputs before attempting to execute its filters and outputs
在一次性发送到output前,单独的工作线程收集的最大的event数量,这个数值太大会消耗更多的内存,进而需要点击进入在 jvm.options 文件配置更高的jvm heap space
125改为4000之后,[提升效果非常明显]
3、pipeline.batch.delay: 50
When creating pipeline event batches, how long in milliseconds to wait for each event before dispatching an undersized batch to pipeline workers.
在创建event batch前,在将一个batch分派给worker之前,每个event batch需要等待多长时间(毫秒)。
50改为20,或者改为100,【效果都不明显】
四、总结
按照如上方法优化之后,logstash的单pod性能平均达到 8000 msg/s
另外,网上有传言说logstash不太稳定。然而持续24小时加压发现,logstash运行非常稳定。