Skip to content

Add regulator to filesystem - #1674

Closed
tonyhb wants to merge 7 commits into
distribution:masterfrom
tonyhb:add-regulator-to-filesystem
Closed

tonyhb wants to merge 7 commits into
distribution:masterfrom
tonyhb:add-regulator-to-filesystem

Conversation

@tonyhb

@tonyhb tonyhb commented Apr 26, 2016 •

Copy link
Copy Markdown
Contributor

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.

Edit:
snip

Josh Hawn and others added 2 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.

Signed-off-by: Tony Holdstock-Brown <[email protected]>
@tonyhb
tonyhb force-pushed the add-regulator-to-filesystem branch from 86aa832 to 115edb4 Compare April 26, 2016 21:44
@tonyhb
tonyhb force-pushed the add-regulator-to-filesystem branch from 115edb4 to ebb0fd3 Compare April 26, 2016 21:47
@RichardScothern

Copy link
Copy Markdown

related: golang/go#7903

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

Copy link
Copy Markdown

Looking good.

This will need documenting in docs/configuration.md and docs/storage-drivers/filesystem.md

tonyhb added 2 commits April 26, 2016 15:20
Signed-off-by: Tony Holdstock-Brown <[email protected]>
Signed-off-by: Tony Holdstock-Brown <[email protected]>
defer r.Signal()
defer r.L.Unlock()

r.available++

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

defer can be somewhat expensive because it involves allocating memory. It's probably okay in the wrapped functions because they wrap filesystem operations that are not exactly cheap, but I was thinking it could be avoided here because there are no return statements in this function.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only signalling when r.available is incremented from 0 might be slightly faster.

@tonyhb
tonyhb force-pushed the add-regulator-to-filesystem branch from d68178a to 1c7f057 Compare May 2, 2016 21:13
@codecov-io

codecov-io commented May 2, 2016 •

Copy link
Copy Markdown

Current coverage is 53.81%

Merging #1674 into master will decrease coverage by -7.86%

  1. 4 files (not in diff) in registry were created. more
  2. 5 files (not in diff) in ...istry/storage/driver were modified. more
    • Misses +812
    • Partials -94
    • Hits -722
  3. 10 files (not in diff) in registry/storage were modified. more
    • Misses +4
    • Partials +5
    • Hits -13
  4. 2 files (not in diff) in registry were modified. more
    • Misses +9
    • Partials +1
    • Hits -10
  5. 2 files (not in diff) in registry/storage were deleted. more
  6. File ...a1/config_builder.go (not in diff) was modified. more
    • Misses 0
    • Partials 0
    • Hits -2
@@             master      #1674   diff @@
==========================================
  Files           120        123      +3   
  Lines         10489      10773    +284   
  Methods           0          0           
  Messages          0          0           
  Branches          0          0           
==========================================
- Hits           6469       5797    -672   
- Misses         3423       4472   +1049   
+ Partials        597        504     -93   

Powered by Codecov. Last updated by 5d08dfa...d68178a

// We only need to signal to a waiting FS operation if we're already at the
// limit of threads used
if r.available == 0 {
defer r.Signal()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't need a defer here.

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.

Was thinking that we only signal after we increment the available count a couple lines below. Would you like this to be removed then?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The waiting operation won't be able to proceed until we release r.L at the end of this function, so I believe it's okay to signal before acutally doing the increment.

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.

Muy bien, on it. Will rebase and squash the commits too.

@aaronlehmann

Copy link
Copy Markdown

Thanks for addressing the feedback!

@aaronlehmann

Copy link
Copy Markdown

Not quite sure what happened here. @SvenDowideit: was this intentionally closed?

@tonyhb

tonyhb commented May 3, 2016

Copy link
Copy Markdown
Contributor Author

@aaronlehmann I'll reopen with a squashed series of commits

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