Skip to content

Add regulator to filesystem - #1695

Merged
RichardScothern merged 4 commits into
distribution:masterfrom
tonyhb:add-regulator-to-filesystem
May 4, 2016
Merged

RichardScothern merged 4 commits into
distribution:masterfrom
tonyhb:add-regulator-to-filesystem

Conversation

@tonyhb

@tonyhb tonyhb commented May 3, 2016

Copy link
Copy Markdown
Contributor

This is a rebased and squashed version of #1674.

The previous PR was as follows:


This PR adds a regulator wrapper around the Filesystem driver.
The regulator ensures that there is an upper bound on the number
of concurrent blocking filesystem operations which spawn new
threads.

By default maxthreads is set to 100. This means the FS driver is
limited to 100 concurrent blocking file operations. Any subsequent
operations will block in Go until previous filesystem operations
complete.

This ensures that the registry can never open thousands of simultaneous
threads from os filesystem operations.

Note that maxthreads can never be less than 25.

PS: Thanks @jlhawn for the regulator implementation.

Josh Hawn and others added 3 commits April 26, 2016 14:44
It's easily possible for a flood of requests to trigger thousands of
concurrent file accesses on the storage driver. Each file I/O call creates
a new OS thread that is not reaped by the Golang runtime. By limiting it
to only 100 at a time we can effectively bound the number of OS threads
in use by the storage driver.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <[email protected]> (github: jlhawn)

Signed-off-by: Tony Holdstock-Brown <[email protected]>
This commit refactors base.regulator into the 2.4 interfaces and adds a
filesystem configuration option `maxthreads` to configure the regulator.

By default `maxthreads` is set to 100. This means the FS driver is
limited to 100 concurrent blocking file operations. Any subsequent
operations will block in Go until previous filesystem operations
complete.

This ensures that the registry can never open thousands of simultaneous
threads from os filesystem operations.

Note that `maxthreads` can never be less than 25.

Add test case covering parsable string maxthreads

Signed-off-by: Tony Holdstock-Brown <[email protected]>
Signed-off-by: Tony Holdstock-Brown <[email protected]>
@RichardScothern

Copy link
Copy Markdown

LGTM (although you could have just pushed to the old PR 😿 )

case uint64:
maxThreads = v
case int, int32, int64:
maxThreads = uint64(reflect.ValueOf(v).Convert(reflect.TypeOf(threads)).Int())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor issue: Should probably check that the value is non-negative before casting it to uint64

@aaronlehmann

Copy link
Copy Markdown

LGTM

}

if maxThreads < minThreads {
maxThreads = minThreads

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, maybe this should log if it's overriding the thread limit because it's too low.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no context is passed to drivers as they're instantiated, so we can't get the logger that's currently in use.

Maybe that could be added as another separate issue?

@RichardScothern

Copy link
Copy Markdown

@SvenDowideit : what is the documentation build saying?


    Changes
Regulate filesystem driver to max of 100 calls (commit: e4dd3359cc3171b98ae34edd8a0a1a19e6d61a6a) (detail / githubweb)
Implement regulator in filesystem driver (commit: 33c448f14769c96d6702f9481831132b06e3cad6) (detail / githubweb)
Add documentation (commit: d0352a7448b17346ad67882cf3df3b1239481d7c) (detail / githubweb)
Don't wrap thead limits when using a negative int (commit: c9c62380ffc1b72a6d1ea1e80cc2d806c750bd9a) (detail / githubweb)

GitHub pull request #1695 of commit c9c62380ffc1b72a6d1ea1e80cc2d806c750bd9a, no merge conflicts.

Run Ownership
Owner
Sven Dowideit
E-mail to Run owners    E-mail to Service owners
    Revision: c9c62380ffc1b72a6d1ea1e80cc2d806c750bd9a
detached
Build Errors:

Add regulator to filesystem: https://github.com/docker/distribution/pull/1695


${FILE:./markdownlint.summary.txt}

@RichardScothern
RichardScothern merged commit c047d34 into distribution:master May 4, 2016
@SvenDowideit SvenDowideit mentioned this pull request May 12, 2016
@RichardScothern RichardScothern added this to the Registry/2.5 milestone Jun 13, 2016
@stevvooe

Copy link
Copy Markdown
Collaborator

Probably not available at the time, but looks like a lot of this code could be replaced with rate.Limiter.

Also, do we have a description of the pathology that led to this change? It's odd to create a driver specific parameter to deal with a Go bug that is triggered by infrastructure conditions. For example, do we know that this resource exhaustion wasn't caused by another bug?

thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Apr 22, 2021
thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Jan 19, 2022
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.

5 participants