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

Heap reported by clinic is very different from that reported by node #458

Open
llimllib opened this issue Aug 28, 2023 · 3 comments
Open

Comments

@llimllib
Copy link

Expected Behavior

  • When I run a test and jest reports that it's using 308 mb of memory, I expect clinic to report that I was using 308 mb of memory

Current Behavior

  • Clinic is off by an order of magnitude

Steps to Reproduce (for bugs)

  1. Run jest under clinic with --logHeapUsage: clinic doctor -- node node_modules/.bin/jest --logHeapUsage packages/models/__tests__/project
  2. Note that jest reports 469 mb max heap usage
  • PASS models packages/models/__tests__/project/model.test.ts (10.117 s, 469 MB heap size)
  1. Note that clinic reports we used ~40:
image

What could be causing such a large difference? Jest uses process.memoryUsage().heapUsed to measure the heap size.

Sample upload

I don't feel comfortable uploading my work app's trace, unfortunately

Environment

  • Clinic.js version: v13.0.0 Doctor v11.0.0
  • Node.js version: v16.20.0 npm 8.19.4
  • Browser name and version: N/A
  • Operating system and version: macOS Ventura 13.4
@RafaelGSS
Copy link
Contributor

I wasn't around when clinic heapprofiler was created so I don't know exactly if that's the expected behaviour. I'm guessing heapprofiler does count the amount of memory allocation during the profile while the process.memoryUsage().heapUsed gets the whole process memory (heap) used -- it's different because the process might hold 10mb but just allocate 1mb in objects.

@mcollina @jasnell would you be able to confirm that?

@llimllib
Copy link
Author

I should have mentioned when I wrote this that --runInBand doesn't change the situation; I suspect it's something to do with the fact that node kicks off a child process. Here's the process tree, as reported by htop during a test run:

image

You can see there that the main jest process only has 86mb, while its child test-runner process is chomping up an order of magnitude more memory.

Is there any way to get at the child process?

@RafaelGSS
Copy link
Contributor

Not really. Heapprofiler measures only the main process, in your case the main jest process.

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

No branches or pull requests

2 participants