Skip to content

Commit

Permalink
etcdctl/check: create new check command for memory usage
Browse files Browse the repository at this point in the history
Create a new command similar to check perf that can check the memory
consumption for putting different workloads. Return user with a message
that whether there are enough memory for a given workload with pass
or fail.

Fixed etcd-io#9121
  • Loading branch information
spzala committed Feb 16, 2018
1 parent aec27a1 commit b16d3ff
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions etcdctl/ctlv3/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,8 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {
r := report.NewReport("%4.4f")
var wg sync.WaitGroup

var statsBefore runtime.MemStats
runtime.ReadMemStats(&statsBefore)
totalOSMemory := statsBefore.Sys
totalAllocBefore := statsBefore.Alloc
wg.Add(len(clients))
fmt.Println(fmt.Sprintf("Start data scale check for work load [%v key-value pairs, %vkb per key-value, %v concurrent clients].", cfg.limit, cfg.kvSize, cfg.clients))
fmt.Println(fmt.Sprintf("Start data scale check for work load [%v key-value pairs, %v bytes per key-value, %v concurrent clients].", cfg.limit, cfg.kvSize, cfg.clients))
for i := range clients {
go func(c *v3.Client) {
defer wg.Done()
Expand All @@ -368,13 +364,13 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {
close(r.Results())
s := <-sc

// check memory consumption
var statsAfter runtime.MemStats
runtime.ReadMemStats(&statsAfter)
totalAllocAfter := statsAfter.Alloc
diffAlloc := totalAllocAfter - totalAllocBefore
// check memory consumption statistics
var stats runtime.MemStats
runtime.ReadMemStats(&stats)
totalAllocMemory := stats.Alloc
totalOSMemory := stats.Sys
// rounded percent of memory consumed
percentAlloc := float64((diffAlloc * 100) / totalOSMemory)
percentAlloc := float64((totalAllocMemory * 100) / totalOSMemory)

ctx, cancel = context.WithCancel(context.Background())
_, err = clients[0].Delete(ctx, checkDatascalePrefix, v3.WithPrefix())
Expand All @@ -392,7 +388,7 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {
ok = false
}

mbUsed := float64(diffAlloc / (1024 * 1024))
mbUsed := float64(totalAllocMemory / (1024 * 1024))
mbTotal := float64(totalOSMemory / (1024 * 1024))

if int(percentAlloc) > 60 { // leaves less than 40 percent of memory
Expand All @@ -401,7 +397,7 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {
} else {
fmt.Println(fmt.Sprintf("PASS: Memory usage is %v%% of available. Expected less than %v%%.", int(percentAlloc), 60))
}
fmt.Println(fmt.Sprintf("INFO: Approx total process memory used : %vmb out of %vmb.", int(mbUsed), int(mbTotal)))
fmt.Println(fmt.Sprintf("INFO: Approximate total process memory used : %vmb out of %vmb.", int(mbUsed), int(mbTotal)))
if ok {
fmt.Println("PASS")
} else {
Expand Down

0 comments on commit b16d3ff

Please sign in to comment.