Repository navigation
Conversation
fa7acd2 to
86aa832
Compare
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]>
86aa832 to
115edb4
Compare
Signed-off-by: Tony Holdstock-Brown <[email protected]>
115edb4 to
ebb0fd3
Compare
|
related: golang/go#7903 |
Signed-off-by: Tony Holdstock-Brown <[email protected]>
|
Looking good. This will need documenting in |
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++ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Only signalling when r.available is incremented from 0 might be slightly faster.
Signed-off-by: Tony Holdstock-Brown <[email protected]>
d68178a to
1c7f057
Compare
Current coverage is 53.81%
@@ 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
|
| // 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() |
There was a problem hiding this comment.
Was thinking that we only signal after we increment the available count a couple lines below. Would you like this to be removed then?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Muy bien, on it. Will rebase and squash the commits too.
|
Thanks for addressing the feedback! |
|
Not quite sure what happened here. @SvenDowideit: was this intentionally closed? |
|
@aaronlehmann I'll reopen with a squashed series of commits |
This PR adds a
regulatorwrapper 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
maxthreadsis set to 100. This means the FS driver islimited 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
maxthreadscan never be less than 25.PS: Thanks jlhawn for the regulator implementation.
Edit:
snip