go-netstat icon indicating copy to clipboard operation
go-netstat copied to clipboard

avoid costly process info extraction if unnecessary

Open sokurenko opened this issue 2 years ago • 0 comments

We need to calculate socket count in listen state and it takes lots of resources to calculate: time ./sbin/zabbix_agent2 -t net.tcp.socket.count[,,,,listen] net.tcp.socket.count[,,,,listen] [s|38983]

user 0m32.999s sys 0m0.470s

However if we modify AcceptFn always to return false and only increase counter when required then everything becomes fast: time ./sbin/zabbix_agent2 -t net.tcp.socket.count[,,,,listen] net.tcp.socket.count[,,,,listen] [s|38983]

user 0m0.143s sys 0m0.296s

However it is possible to improve even further with the fix in pull request: time ./sbin/zabbix_agent2 -t net.tcp.socket.count[,,,,listen] net.tcp.socket.count[,,,,listen] [s|38983]

user 0m0.060s sys 0m0.069s

Please accept pull request, also it would be nice to document that AcceptFn can be used to calculate data without returning it as it is pretty CPU intensive, thank you!

This is required for https://support.zabbix.com/browse/ZBX-21300

sokurenko avatar Jul 15 '22 15:07 sokurenko