childe / gohangout

使用 golang 模仿的 Logstash。用于消费 Kafka 数据,处理后写入 ES、Clickhouse 等。
MIT License
1.01k stars 234 forks source link

json库占用cpu比较高 #115

Closed MaxWk closed 3 years ago

MaxWk commented 3 years ago

我们在线上跑的cpu一直在80%以上,我用火焰图看了一下,发现json decode这块占用非常高。后面看到一些分析说json-iterator 这个三方库相比go的原声库性能已经不占优势了。 参考: https://my.oschina.net/childewang/blog/3029203 https://github.com/json-iterator/go/issues/320 image

childe commented 3 years ago

Json 编解码性能的确是不太行, 不管哪个库. 不过既然Go原生库在某些场景下更好, 那的确是可以试一下换到原生库.

MaxWk commented 3 years ago

测试了一波,go1.13.15 下原生比目前cpu反而更高。所以根本原因应该还是decode成map而不是struct。这里也没什么好的解决方案。这个issue先关了吧