Skip to content

cluster:take a worker offline and force GC

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

I am trying optimize my application which requires high memory utilization, the application is built using React JavaScript library, and server handles high RPS. But we encountered high latency due to frequent GC operation. We have optimized the application code as much as possible in order to reduce the latency caused by GC.

I have tweaked cluster.js to reduce the latency further down. With the tweak, I've been able to reduce the latency by substantially for the median(improved by more 300ms), 95th(improved by more than 600ms) and 99th percentiles(improved by more than 1s) of response time.

Here is how it works, normally my application runs with 23 workers run on a 12core/24thread machine. With the tweaked version of cluster.js, I increased the number of workers by X amount(lets say five), so at any given time 5 workers will be inactive and perform GC while they are inactive. The idea is to rotate the workers from online/listening state to inactive state and force GC on a worker while it's inactive. As soon as the GC is completed the work is put back to listening state in order to server more incoming requests, in its place another work is taken offline for GC.

Merge request reports

Loading