statsd-filter-proxy-rs icon indicating copy to clipboard operation
statsd-filter-proxy-rs copied to clipboard

Few optimization for NodeJS version

Open corporatepiyush opened this issue 4 years ago • 0 comments

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.

  1. Use latest version of NodeJS
  2. extract error handling function outside which is registered to "client.send" method
  3. Run >> node --expose-gc --inspect statsd-filter-proxy.js
  4. 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.
  5. Consider receiving, storing and sending packets in batch rather than one by one
  6. 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/
  7. use "taskset" linux command to pin nodejs process to particular CPU core instead of all the cores which the default, this ensures maximum yield

corporatepiyush avatar May 08 '21 08:05 corporatepiyush