-
Notifications
You must be signed in to change notification settings - Fork 120
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
Avoid launching too many goroutines during caching layer #157
Conversation
stargz/reader/reader.go
Outdated
return gr.cacheWithReader(root, r, filter, cacheOpts.cacheOpts...) | ||
eg, egCtx := errgroup.WithContext(context.Background()) | ||
eg.Go(func() error { | ||
return gr.cacheWithReader(egCtx, eg, semaphore.NewWeighted(4), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semaphore.NewWeighted(4)
Should this correspond to GOMAXPROCS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, is it really allowed to recursively call eg.Go
from eg.Go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing this.
Should this correspond to GOMAXPROCS?
Fixed it on the latest push.
Curious, is it really allowed to recursively call eg.Go from eg.Go?
According to golang/go#27837 (comment), this seems an allowed pattern.
Thanks for the promt reply and super fast proposal! The situation is better with this patch.
bad :(
|
@strigazi Thanks for trying this patch!
What's the stack trace showing? This might be related to the recursive |
|
Currently `reader.Cache()` creates goroutines for each file contained in the layer. This can lead to too many goroutines and possibly consume too much resource. This commit fixes it by limiting the number of goroutines using semaphore. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
If a tar layer contains "./" at root (which points to root itself), this will cause infinite recursive call during caching layer and lead to panic (`goroutine stack exceeds`). This commit fixes it. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
@strigazi Thanks for providing the log. That panic was because of an infinite recursive call of
|
Thanks @ktock , it looks good now! Low number of goroutines for the images that I tried, CPU utilization is normal. |
#156
Currently
reader.Cache()
creates goroutines for each file contained in thelayer. This can lead to too many goroutines and possibly consume too much
resource.
This commit fixes it by limiting the number of goroutines using semaphore.
cc: @strigazi