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(user-data): use semaphore to limit reads COMPASS-7256 #6427

Merged
merged 4 commits into from
Nov 4, 2024

Conversation

mabaasit
Copy link
Contributor

Description

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the fix label Oct 31, 2024
@@ -68,6 +69,7 @@ export class UserData<T extends z.Schema> {
private readonly serialize: SerializeContent<z.input<T>>;
private readonly deserialize: DeserializeContent;
private readonly getFileName: GetFileName;
private readonly semaphore = new Semaphore(1000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Node.js thread pool for fs operations (UV_THREADPOOL_SIZE) has a default size of 4 or so. I think a lower number, say 50 or 100, would also be fine here and result in similar performance while at the same time still being significantly better at reducing the risk of EMFILE/ENFILE errors


await Promise.all(
files.map(([filepath, data]) => writeFileToStorage(filepath, data))
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this test also run the risk of running into file descriptor limitations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's a good point. i'll remove this test.

@mabaasit mabaasit merged commit 93fc170 into main Nov 4, 2024
30 checks passed
@mabaasit mabaasit deleted the COMPASS-7256-read-files branch November 4, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants