From 021b8c4cff213dbceb5348f3f6a480edda2a6f69 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 20 Jul 2018 01:04:51 +0300 Subject: [PATCH] Lower memory usage for `aptly db cleanup` This is not a complete fix, but the easiest first step. During `db cleanup`, aptly is loading every repo/mirror/... into memory, and even though each object is processed only once, collection holds a reference to all the loaded objects, so they won't be GC'd until process exits. CollectionFactory.Flush() releases pointers to collection objects, making objects egligble for GC. This is not a complete fix, as during iteration we could have tried to release a link to every object being GCed and that would have helped much more. --- cmd/db_cleanup.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/db_cleanup.go b/cmd/db_cleanup.go index 4a1b0535b..be246915d 100644 --- a/cmd/db_cleanup.go +++ b/cmd/db_cleanup.go @@ -59,6 +59,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { return err } + context.CollectionFactory().Flush() + if verbose { context.Progress().ColoredPrintf("@{y}Loading local repos:@|") } @@ -90,6 +92,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { return err } + context.CollectionFactory().Flush() + if verbose { context.Progress().ColoredPrintf("@{y}Loading snapshots:@|") } @@ -118,6 +122,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { return err } + context.CollectionFactory().Flush() + if verbose { context.Progress().ColoredPrintf("@{y}Loading published repositories:@|") } @@ -150,6 +156,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { return err } + context.CollectionFactory().Flush() + // ... and compare it to the list of all packages context.Progress().ColoredPrintf("@{w!}Loading list of all packages...@|") allPackageRefs := context.CollectionFactory().PackageCollection().AllPackageRefs() @@ -192,6 +200,8 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error { } } + context.CollectionFactory().Flush() + // now, build a list of files that should be present in Repository (package pool) context.Progress().ColoredPrintf("@{w!}Building list of files referenced by packages...@|") referencedFiles := make([]string, 0, existingPackageRefs.Len())