Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rss memory leak #16

Closed
twoeths opened this issue Jan 10, 2023 · 0 comments · Fixed by #17
Closed

Rss memory leak #16

twoeths opened this issue Jan 10, 2023 · 0 comments · Fixed by #17
Assignees

Comments

@twoeths
Copy link

twoeths commented Jan 10, 2023

There is a rss memory leak issue found from ChainSafe/lodestar#4623

to reproduce:

import {ssz} from "@lodestar/types";
import snappy from "@chainsafe/snappy-stream";

// could be any data
const singleBlockBytes = ssz.bellatrix.SignedBeaconBlock.serialize(ssz.bellatrix.SignedBeaconBlock.defaultValue());

async function memTest(): Promise<void> {
  const count = 1_000_000_000;
  for (let i = 0; i < count; i++) {
    const stream = snappy.createCompressStream();
    stream.write(singleBlockBytes);
    stream.end();
    if (i % 100_000 === 0) {
      await new Promise((resolve) => setTimeout(resolve, 100));
      const {heapTotal, rss} = process.memoryUsage();
      console.log(
        "Memory usage",
        Math.floor((i * 100) / count) + "%",
        "heapTotal",
        toMem(heapTotal),
        "rss",
        toMem(rss)
      );
    }
  }
}

some output

Memory usage 4% heapTotal +384.67 MB rss +5.01 GB
Memory usage 4% heapTotal +565.29 MB rss +5.3 GB
Memory usage 4% heapTotal +745.65 MB rss +5.56 GB
Memory usage 4% heapTotal +932.56 MB rss +5.65 GB
Memory usage 4% heapTotal +1.11 GB rss +5.78 GB
Memory usage 4% heapTotal +409.32 MB rss +4.99 GB
Memory usage 4% heapTotal +563.2 MB rss +5.25 GB

heap total is not leaked but rss keeps increasing, it seems "@chainsafe/fast-crc32c" is the root cause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant