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

Use sleep in flock wait loop #12861

Merged

Conversation

straight-shoota
Copy link
Member

Since #12728, when a file lock can't be attained immediately, blocking flock waits in a loop an tries again until the lock becomes available.

As commented in #12728 (comment), the relatively tight loop with Fiber.yield can drive up CPU utilization.

This patch lets the fiber sleep for 100ms. That amount isn't set in stone, but it's probably a good start. I've copied it from the Ruby implementation: https://github.com/ruby/ruby/blob/5404e2fd31736af3a7477f3ec67d3f07276485d6/file.c#L5283-L5308

Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

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

Thanks @straight-shoota and thanks @russdill for noting it

@straight-shoota straight-shoota added this to the 1.7.0 milestone Dec 21, 2022
@straight-shoota straight-shoota merged commit 9e47a2d into crystal-lang:master Dec 22, 2022
@straight-shoota straight-shoota deleted the fix/flock-sleep branch December 22, 2022 10:14
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.

None yet

2 participants