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

Reduce memory usage in long-running processes #14885

Merged
merged 6 commits into from
Oct 29, 2024
Merged

Reduce memory usage in long-running processes #14885

merged 6 commits into from
Oct 29, 2024

Conversation

Jarred-Sumner
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner commented Oct 29, 2024

What does this PR do?

New:

┌─────────────────────────┬──────────┐
│                         │ Values   │
├─────────────────────────┼──────────┤
│   Memory usage MB (RSS) │ 650      │
│ AbortSignal alive count │ 200002   │
│ new AbortSignal() calls │ 55500000 │
│        Uptime (seconds) │ 630      │
└─────────────────────────┴──────────┘

Previously:

┌─────────────────────────┬──────────┐
│                         │ Values   │
├─────────────────────────┼──────────┤
│   Memory usage MB (RSS) │ 678      │
│ AbortSignal alive count │ 495616   │
│ new AbortSignal() calls │ 55500000 │
│        Uptime (seconds) │ 630      │
└─────────────────────────┴──────────┘

For the following script:

console.clear();
console.log("Starting...");
const iterationCount = 100000;
globalThis.signals = new Array(iterationCount);
globalThis.requests = new Array(iterationCount);
var total = 0;
setInterval(() => {
  const rss = (process.memoryUsage.rss() / 1024 / 1024) | 0;
  const objectTypeCounts = require("bun:jsc").heapStats().objectTypeCounts;
  console.table({
    "Memory usage MB (RSS)": rss,
    "AbortSignal alive count": objectTypeCounts.AbortSignal || 0,
    "new AbortSignal() calls": total,
    "Uptime (seconds)": Math.floor(process.uptime()),
  });
}, 10000);
while (true) {
  for (let i = 0; i < iterationCount; i++) {
    const req = new Request("https://example.com/");
    requests[i] = req;
    signals[i] = AbortSignal.any([req.signal, new AbortController().signal]);
  }
  total += iterationCount;
  await Bun.sleep(1000);
}

How did you verify your code works?

CI

@robobun
Copy link

robobun commented Oct 29, 2024

@Jarred-Sumner Jarred-Sumner changed the title Copy event loop changes from node:http branch Reduce memory usage in long-running processes Oct 29, 2024
@Jarred-Sumner Jarred-Sumner marked this pull request as ready for review October 29, 2024 08:30
@Jarred-Sumner Jarred-Sumner merged commit b5a7313 into main Oct 29, 2024
40 of 44 checks passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/loop branch October 29, 2024 19:56
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 this pull request may close these issues.

2 participants