avoid costly process info extraction if unnecessary both on Linux and Windows #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
And on Windows tested with 30000k sockets and it takes too long (waited for more than 30 seconds and there was still no result):
But after changes it only took 398ms
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