Skip to content

Commit

Permalink
Merge pull request #2427 from hashicorp/f-gc-limit
Browse files Browse the repository at this point in the history
Limit parallelism during garbage collection
  • Loading branch information
dadgar committed Mar 14, 2017
2 parents 7605d9a + 38ebed5 commit 97a4e13
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 127 deletions.
8 changes: 5 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func NewClient(cfg *config.Config, consulSyncer *consul.Syncer, logger *log.Logg
DiskUsageThreshold: cfg.GCDiskUsageThreshold,
InodeUsageThreshold: cfg.GCInodeUsageThreshold,
Interval: cfg.GCInterval,
ParallelDestroys: cfg.GCParallelDestroys,
ReservedDiskMB: cfg.Node.Reserved.DiskMB,
}
c.garbageCollector = NewAllocGarbageCollector(logger, statsCollector, gcConfig)
Expand Down Expand Up @@ -1832,10 +1833,11 @@ func (c *Client) removeAlloc(alloc *structs.Allocation) error {
delete(c.allocs, alloc.ID)
c.allocLock.Unlock()

// Remove the allocrunner from garbage collector
c.garbageCollector.Remove(ar)
// Ensure the GC has a reference and then collect. Collecting through the GC
// applies rate limiting
c.garbageCollector.MarkForCollection(ar)
go c.garbageCollector.Collect(alloc.ID)

ar.Destroy()
return nil
}

Expand Down
13 changes: 9 additions & 4 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ type Config struct {
// collection
GCInterval time.Duration

// GCDiskUsageThreshold is the disk usage threshold beyond which the Nomad
// client triggers GC of terminal allocations
// GCParallelDestroys is the number of parallel destroys the garbage
// collector will allow.
GCParallelDestroys int

// GCDiskUsageThreshold is the disk usage threshold given as a percent
// beyond which the Nomad client triggers GC of terminal allocations
GCDiskUsageThreshold float64

// GCInodeUsageThreshold is the inode usage threshold beyond which the Nomad
// client triggers GC of the terminal allocations
// GCInodeUsageThreshold is the inode usage threshold given as a percent
// beyond which the Nomad client triggers GC of the terminal allocations
GCInodeUsageThreshold float64

// LogLevel is the level of the logs to putout
Expand Down Expand Up @@ -194,6 +198,7 @@ func DefaultConfig() *Config {
TLSConfig: &config.TLSConfig{},
LogLevel: "DEBUG",
GCInterval: 1 * time.Minute,
GCParallelDestroys: 2,
GCDiskUsageThreshold: 80,
GCInodeUsageThreshold: 70,
}
Expand Down
Loading

0 comments on commit 97a4e13

Please sign in to comment.