statsd-filter-proxy-rs
statsd-filter-proxy-rs copied to clipboard
Few optimization for NodeJS version
I came here after reading the post of medium - https://medium.com/tenable-techblog/optimizing-700-cpus-away-with-rust-dc7a000dbdb2
Although I don't think JS is going beat Rust but I have few suggestions to improve the performance characteristics of the code.
- Use latest version of NodeJS
- extract error handling function outside which is registered to "client.send" method
- Run >> node --expose-gc --inspect statsd-filter-proxy.js
- The most import step is to do little experiment with socket.setRecvBufferSize(size) and socket.setSendBufferSize(size) can give you optimum size of buffer which can help in reducing the GC pressure on heap.
- Consider receiving, storing and sending packets in batch rather than one by one
- Explicitly set the heap size >> node --max-old-space-size=10240 statsd-filter-proxy.js. here the number for 10240 is just an example, not a concrete suggestion. First 5 steps will help you to come to actual number. Similarily set the value of min_semi_space_size, max_semi_space_size. more info here, https://deepu.tech/memory-management-in-v8/
- use "taskset" linux command to pin nodejs process to particular CPU core instead of all the cores which the default, this ensures maximum yield