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

fix: add concurrency limit to fs calls #301

Merged
merged 5 commits into from
Jul 19, 2022
Merged

Conversation

Brooooooklyn
Copy link
Contributor

@Brooooooklyn Brooooooklyn commented Jul 15, 2022

This adds concurrency limits to our fs calls to attempt to alleviate memory issues with too many promises being stored in memory at once.

x-ref: slack thread

@codecov
Copy link

codecov bot commented Jul 15, 2022

Codecov Report

Merging #301 (bed01ad) into main (11c6888) will increase coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
+ Coverage   80.45%   80.57%   +0.11%     
==========================================
  Files          13       13              
  Lines        1489     1498       +9     
  Branches      555      556       +1     
==========================================
+ Hits         1198     1207       +9     
  Misses        121      121              
  Partials      170      170              
Impacted Files Coverage Δ
src/node-file-trace.ts 88.00% <100.00%> (+0.50%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

src/node-file-trace.ts Outdated Show resolved Hide resolved
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

package.json Outdated Show resolved Hide resolved
src/node-file-trace.ts Outdated Show resolved Hide resolved
styfle
styfle previously requested changes Jul 15, 2022
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a PR description. Also can you add a test to prove this fixes it? (presumably this is fixing something due to the title of the PR?)

@ijjk ijjk changed the title fix: add concurrency limit to readlink fix: add concurrency limit to fs calls Jul 15, 2022
src/node-file-trace.ts Outdated Show resolved Hide resolved
src/node-file-trace.ts Outdated Show resolved Hide resolved
try {
const link = await fsReadlink(path);
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't async operations.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

@@ -162,6 +170,7 @@ export class Job {
return link;
}
catch (e) {
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

try {
const stats = await fsStat(path);
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

this.statCache.set(path, stats);
return stats;
}
catch (e) {
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

try {
const source = (await fsReadFile(path)).toString();
this.fileCache.set(path, source);
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

return source;
}
catch (e) {
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.fileIOQueue.release();
this.fileIOQueue.release();

Comment on lines 225 to 226
this.fileCache.set(path, source);
await this.fileIOQueue.release();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Flip these to make it consistent with the others:

Suggested change
this.fileCache.set(path, source);
await this.fileIOQueue.release();
this.fileIOQueue.release();
this.fileCache.set(path, source);

@@ -79,6 +81,9 @@ export class Job {
ts = true,
analysis = {},
cache,
// we use a default of 1024 concurrency to balance
// performance and memory usage for fs operations
fileIOConcurrency = Number(process.env.FILE_IO_CONCURRENCY) || 1024,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let not use an env var. Instead, the consumer should pass the fileIOConcurrency option to nodeFileTrace()

We also need to update the README.md with the new option

@Brooooooklyn Brooooooklyn requested a review from styfle July 19, 2022 03:16
src/node-file-trace.ts Outdated Show resolved Hide resolved
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ijjk ijjk added the automerge Automatically merge PR once checks pass label Jul 19, 2022
@kodiakhq kodiakhq bot merged commit af3051a into main Jul 19, 2022
@kodiakhq kodiakhq bot deleted the add-limit-to-readlink branch July 19, 2022 17:12
kodiakhq bot pushed a commit to vercel/vercel that referenced this pull request Jul 22, 2022
### Related Issues

Updates to the latest version of `@vercel/nft` which adds fs concurrency limits to help alleviate memory usage. 

x-ref: vercel/nft#301

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants