Skip to content

Commit

Permalink
llrb: remove memutilization parameter from settings.
Browse files Browse the repository at this point in the history
- Refactor validatemem, if ExpectedUtilization is set 1% or less
  validatemem will execute as NO-OP.
  • Loading branch information
prataprc committed Jul 25, 2017
1 parent 0f2370d commit 4e4abee
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion llrb/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (llrb *LLRB) rvrsltht(
return llrb.rvrsltht(nd.left, lk, hk, callb)
}

// costly operation, don't call this one active trees.
// costly operation, don't call this on active trees.
func (llrb *LLRB) treecheck(
nd *Llrbnode, depth int64, h *lib.HistogramInt64, count int64) int64 {

Expand Down
15 changes: 5 additions & 10 deletions llrb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import "github.com/cloudfoundry/gosigar"

// Defaultsettings for llrb instance along with node arena and value arena.
//
// Configuration parameters:
// "iterpool.size": int64(100)
// Maximum number of active iterators. Each Iterate call will acquire
// an instance of iterator.
//
// "iterpool.size": int64(100),
// maximum number of active iterators.
//
// "lsm": false,
// Enable Log-Structured-Merge feature.
//
// "memutilization": float64(0.4),
// allowable memory utilization.
// "lsm": false
// Enable Log-Structured-Merge feature.
//
// "minkeysize" (int64, default: <api.MinKeysize>),
// minimum size allowed for key.
Expand Down Expand Up @@ -81,7 +77,6 @@ func Defaultsettings() s.Settings {
setts := s.Settings{
"iterpool.size": int64(100),
"lsm": false,
"memutilization": float64(0.4),
"minkeysize": api.MinKeysize,
"maxkeysize": api.MaxKeysize,
"minvalsize": api.MinValsize,
Expand Down
1 change: 0 additions & 1 deletion llrb/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (llrb *LLRB) readsettings(setts s.Settings) {
llrb.mvcc.enabled = setts.Bool("mvcc.enable")
llrb.writechansz = setts.Int64("mvcc.writer.chansize")
llrb.snaptick = setts.Int64("mvcc.snapshot.tick")
llrb.memutilization = setts.Float64("memutilization")
}

func (llrb *LLRB) newnodearena(capacity int64, setts s.Settings) *malloc.Arena {
Expand Down
5 changes: 5 additions & 0 deletions llrb/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (llrb *LLRB) stats() (map[string]interface{}, error) {
return stats, nil
}

// along with basic tree statistics, walks the tree to gather:
// * histogram of tree-height
// * number blacks, also make sures that number of blacks
// on the left path patches with number of blacks on the right
// path. this is a basic llrb invariant.
func (llrb *LLRB) fullstats() (map[string]interface{}, error) {
stats, err := llrb.stats()
if err != nil {
Expand Down
55 changes: 29 additions & 26 deletions llrb/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,44 @@ func (llrb *LLRB) validate(root *Llrbnode) {
}

func (llrb *LLRB) validatemem() {
dohumanize := func(val interface{}) interface{} {
return gohumanize.Bytes(uint64(val.(int64)))
stats := llrb.statsval(llrb.statskey(make(map[string]interface{})))
entries := llrb.Count()
memuz := llrb.memutilization
if memuz < 0.01 { // skip if less than 1%
return
}

meminfo := func(args ...string) string {
vals := []interface{}{entries}
for _, arg := range args {
vals = append(vals, gohumanize.Bytes(uint64(stats[arg].(int64))))
}
fmsg := "entries(%v/%v): cap: %v {heap:%v,alloc:%v,overhd:%v}"
return fmt.Sprintf(fmsg, vals...)
}

stats := llrb.statsval(llrb.statskey(make(map[string]interface{})))
memory := float64(llrb.keymemory)
heap := float64(stats["node.heap"].(int64))
entries := llrb.Count()
ratio := memory / heap
if ratio < llrb.memutilization {
capac := dohumanize(stats["node.capacity"])
overh := dohumanize(stats["node.overhead"])
heap := dohumanize(stats["node.heap"])
alloc := dohumanize(stats["node.alloc"])
kmem := dohumanize(stats["keymemory"])
fmsg := "%v keymem(%v): cap: %v {heap:%v,alloc:%v,overhd,%v}\n"
log.Infof(fmsg, llrb.logprefix, kmem, capac, heap, alloc, overh)
panic(fmt.Errorf(
"keys(%v): ratio: %0.2f%% %v {%v/%v}",
entries, ratio*100, llrb.memutilization*100, memory, heap))
if ratio < memuz {
info := meminfo(
"keymemory", "node.capacity", "node.heap", "node.alloc",
"node.overhead",
)
log.Infof("%v %v\n", llrb.logprefix, info)
panic(fmt.Errorf("%v/%v=%v < %v", memory, heap, ratio*100, memuz*100))
}

memory = float64(llrb.valmemory)
heap = float64(stats["value.heap"].(int64))
ratio = memory / heap
if ratio < llrb.memutilization {
capac := dohumanize(stats["value.capacity"])
overh := dohumanize(stats["value.overhead"])
heap := dohumanize(stats["value.heap"])
alloc := dohumanize(stats["value.alloc"])
vmem := dohumanize(stats["valmemory"])
fmsg := "%v valmem(%v): cap: %v {heap:%v,alloc:%v,overhd:%v}\n"
log.Infof(fmsg, llrb.logprefix, vmem, capac, heap, alloc, overh)
panic(fmt.Errorf(
"values(%v): ratio: %0.2f%% %v {%v/%v}",
entries, ratio*100, llrb.memutilization*100, memory, heap))
if ratio < memuz {
info := meminfo(
"valmemory", "value.capacity", "value.heap", "value.alloc",
"value.overhead",
)
log.Infof("%v %v\n", llrb.logprefix, info)
panic(fmt.Errorf("%v/%v=%v < %v", memory, heap, ratio*100, memuz*100))
}
}

Expand Down

0 comments on commit 4e4abee

Please sign in to comment.