Exemple #1
0
func withLLRB(count int, outch chan [][]interface{}) {
	d := llrb.NewDict()
	ds := llrb.NewLLRB()
	stats := make(map[string]int)
	for count > 0 {
		count--
		cmds := <-outch
		for _, cmd := range cmds {
			stats = validate(d, ds, cmd, stats)
		}
	}
	validateEqual(d, ds)
	printStats(stats)
	avg, sd := ds.HeightStats()
	fmt.Printf("LLRB Stats: avg-height: %4.2f, sd-height: %4.2f\n", avg, sd)
}
Exemple #2
0
func withLLRBMVCC(count int, outch chan [][]interface{}) {
	d := llrb.NewDict()
	w := llrb.NewLLRBMVCC(10)
	quitch := make(chan bool)
	readers := make(map[int][]interface{})
	for i := 0; i < 4; i++ {
		inpch := make(chan []interface{}, 4)
		rstats := make(map[string]int)
		readers[i] = []interface{}{inpch, rstats}
		go concurrent_reader(inpch, rstats, quitch)
		inpch <- []interface{}{"snapshot", d.RSnapshot(100), w.RSnapshot(100)}
	}

	total := 0
	stats := make(map[string]int)
	snapstick := time.Tick(100 * time.Millisecond) // take snapshot per 100ms
	for count > 0 {
		count--
		select {
		case cmds := <-outch:
			for _, cmd := range cmds {
				total++
				if isReadOp(cmd) {
					for _, reader := range readers {
						reader[0].(chan []interface{}) <- cmd
					}
				} else {
					stats = validate(d, w, cmd, stats)
				}
			}

		case <-snapstick:
			for i, reader := range readers {
				if i >= total%4 {
					break
				}
				d := d.RSnapshot(100)
				ds := w.RSnapshot(100)
				reader[0].(chan []interface{}) <- []interface{}{"snapshot", d, ds}
			}
		}
	}

	// close readers
	for _, reader := range readers {
		close(reader[0].(chan []interface{}))
	}
	// wait for reader routines to quit.
	count = len(readers)
	for count > 0 {
		<-quitch
		count--
	}

	validateEqual(d, w)
	fmt.Printf("total number of commands: %v\n", total)
	fmt.Println("stats for writer:")
	printStats(stats)
	for _, reader := range readers {
		fmt.Println("stats for reader:")
		printStats(reader[1].(map[string]int))
	}
	avg, sd := w.HeightStats()
	fmt.Printf("LLRB Stats: avg-height: %4.2f, sd-height: %4.2f\n", avg, sd)
	for opname := range writeOps {
		avg, sd := w.CowStats(opname)
		fmt.Printf("COW %s: avg-cow: %4.2f, sd-cow: %4.2f\n", opname, avg, sd)
	}
}