summaryrefslogtreecommitdiff
path: root/cmd/podman/rm.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-10-12 14:07:33 -0500
committerbaude <bbaude@redhat.com>2018-10-22 17:06:30 -0500
commitfc4b34c8c02b9f29be4a2123c4f7d6c1c6aa6ef3 (patch)
tree6a522be9ee83b9761cc98781a520fbf3249171af /cmd/podman/rm.go
parent5b2478ed87eedd8178c1672a786f95a6716a8edb (diff)
downloadpodman-fc4b34c8c02b9f29be4a2123c4f7d6c1c6aa6ef3.tar.gz
podman-fc4b34c8c02b9f29be4a2123c4f7d6c1c6aa6ef3.tar.bz2
podman-fc4b34c8c02b9f29be4a2123c4f7d6c1c6aa6ef3.zip
Make rm faster
When doing rm, we now parallelize the actual conainter deletions so they can complete faster. This speeds up operations like rm -a. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/rm.go')
-rw-r--r--cmd/podman/rm.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go
index f64eca6f4..38b1546ff 100644
--- a/cmd/podman/rm.go
+++ b/cmd/podman/rm.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
+ rt "runtime"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
@@ -45,6 +46,12 @@ Running containers will not be removed without the -f option.
// saveCmd saves the image to either docker-archive or oci
func rmCmd(c *cli.Context) error {
+ var (
+ delContainers []*libpod.Container
+ lastError error
+ deleteFuncs []workerInput
+ )
+
ctx := getContext()
if err := validateFlags(c, rmFlags); err != nil {
return err
@@ -65,8 +72,6 @@ func rmCmd(c *cli.Context) error {
return errors.Errorf("specify one or more containers to remove")
}
- var delContainers []*libpod.Container
- var lastError error
if c.Bool("all") {
delContainers, err = runtime.GetContainers()
if err != nil {
@@ -89,16 +94,26 @@ func rmCmd(c *cli.Context) error {
delContainers = append(delContainers, container)
}
}
+
for _, container := range delContainers {
- err = runtime.RemoveContainer(ctx, container, c.Bool("force"))
- if err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "failed to delete container %v", container.ID())
- } else {
- fmt.Println(container.ID())
+ f := func() error {
+ return runtime.RemoveContainer(ctx, container, c.Bool("force"))
+ }
+
+ deleteFuncs = append(deleteFuncs, workerInput{
+ containerID: container.ID(),
+ parallelFunc: f,
+ })
+ }
+
+ deleteErrors := parallelExecuteWorkerPool(rt.NumCPU()*3, deleteFuncs)
+ for cid, result := range deleteErrors {
+ if result != nil {
+ fmt.Println(result.Error())
+ lastError = result
+ continue
}
+ fmt.Println(cid)
}
return lastError
}