Exemple #1
0
func argParse() {
	var ops string
	var algo string
	flag.IntVar(&options.bcount, "count", 1,
		"data set size")
	flag.IntVar(&options.readers, "readers", 2,
		"number of concurrent readers to use with MVCC")
	flag.StringVar(&options.pprof, "pprof", "",
		"filename to save pprof o/p")
	flag.StringVar(&options.mprof, "mprof", "",
		"filename to save mprof o/p")
	flag.StringVar(&ops, "ops", "",
		"operations to profile")
	flag.StringVar(&algo, "algo", "llrb",
		"operations to profile")
	flag.IntVar(&options.mtick, "mtick", 0,
		"periodic tick to dump mem-stat, in mS")
	flag.Parse()

	options.ops = make([]string, 0)
	for _, op := range strings.Split(ops, ",") {
		if strings.Trim(op, " ") == "" {
			continue
		}
		options.ops = append(options.ops, op)
	}
	options.algo = make(map[string]llrb.MemStore)
	for _, algo := range strings.Split(algo, ",") {
		if strings.Trim(algo, " ") == "" {
			continue
		}
		switch algo {
		case "llrb":
			options.algo[algo] = llrb.NewLLRB()
		case "mvcc":
			options.algo[algo] = llrb.NewLLRBMVCC(10)
		}
	}
}
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)
	}
}