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

fix nerdctl ps slow on heavy IO system by using goroutine #3673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ningmingxiao
Copy link
Contributor

@ningmingxiao ningmingxiao commented Nov 13, 2024

formatter.ContainerStatus will use some time. If plenty of calls are coming, this will use much time.
before

time nerdctl_old -n k8s.io  ps -a
real    2m27.206s
user    0m0.336s
sys     0m0.218s

after this commit

time nerdctl_new -n k8s.io  ps -a
real    0m3.333s
user    0m0.145s
sys     0m0.074s

@AkihiroSuda

@ningmingxiao ningmingxiao changed the title fix nerdctl ps slow by using goroutine fix nerdctl ps slow on heavy IO system by using goroutine Nov 13, 2024
pkg/cmd/container/list.go Outdated Show resolved Hide resolved
pkg/cmd/container/list.go Outdated Show resolved Hide resolved
Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

// formatter.ContainerStatus(ctx, c) is time consuming so we do it in goroutines and return the container's id with status as a map.
// prepareContainers func will use this map to avoid call formatter.ContainerStatus again.
for _, c := range containers {
wg.Add(1)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
wg.Add(1)
c := c
wg.Add(1)

the above line code simplifies the code and avoid using a mutex, right ?

Copy link
Member

Choose a reason for hiding this comment

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

@ningmingxiao WDYT ?

pkg/cmd/container/list.go Outdated Show resolved Hide resolved
pkg/cmd/container/list.go Outdated Show resolved Hide resolved
pkg/cmd/container/list.go Outdated Show resolved Hide resolved
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
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.

4 participants