Skip to content

Add a concurrency limit on FileWriter ops. #9857

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

Merged
merged 5 commits into from
Jul 10, 2025

Conversation

vadimberezniker
Copy link
Member

@vadimberezniker vadimberezniker commented Jul 9, 2025

FileWriters are used to write artifacts to disk by the cache implementations. When there are bursts of file writer operations, it can cause the Go runtime to create an unbounded number of system threads as file writer ops end up blocked on syscalls.

The concurrency limit places an upper bound on the system threads created via this code path.

Fixes: https://github.com/buildbuddy-io/buildbuddy-internal/issues/5325

FileWriters are used to write artifacts to disk by the cache
implementations. When there are bursts of file writer operations, it can
cause the Go runtime to create an unbounded number of system threads as
file writer ops end up blocked on syscalls.

The concurrency limit places an upper bound on the system threads
created via this code path.
if err != nil {
return nil, err
}
defer releaseQuota()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit conflicted here. In some ways, I think it would be better to get quota once and hold on to it until the writer is closed. That way, there's less overhead for getting quota, plus we would prefer to finish ongoing writes instead of starting new ones.

On the other hand, it seems bad to hold on to the quota while we're not doing anything, or maybe just receiving the next chunk from the client.

Anyway, this seems ok as is, unless there's some benchmark that shows a proble.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only limit we are currently encountering in practice is on the number of blocked syscalls which is what this PR is trying to address. Having a limit on the total number of writers also makes sense, but I think that needs to be handled and configured separately from this limit.

@vadimberezniker vadimberezniker requested a review from vanja-p July 9, 2025 22:59
@vadimberezniker vadimberezniker merged commit 1fb9589 into master Jul 10, 2025
12 of 14 checks passed
@vadimberezniker vadimberezniker deleted the disk_writer_concurrency branch July 10, 2025 00:26
vadimberezniker added a commit that referenced this pull request Jul 10, 2025
FileWriters are used to write artifacts to disk by the cache
implementations. When there are bursts of file writer operations, it can
cause the Go runtime to create an unbounded number of system threads as
file writer ops end up blocked on syscalls.

The concurrency limit places an upper bound on the system threads
created via this code path.

Fixes: buildbuddy-io/buildbuddy-internal#5325
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.

4 participants