示例#1
0
文件: main.go 项目: jyzhe/beehive
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	if *quiet {
		log.SetOutput(ioutil.Discard)
	}

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			glog.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	opts := []bh.AppOption{bh.Persistent(*replFactor)}
	if *random {
		rp := bh.RandomPlacement{
			Rand: rand.New(rand.NewSource(time.Now().UnixNano())),
		}
		opts = append(opts, bh.Placement(rp))
	}
	a := bh.NewApp("kvstore", opts...)
	kv := &store.KVStore{
		Hive:    bh.DefaultHive,
		Buckets: uint64(*buckets),
	}
	a.Handle(store.Put{}, kv)
	a.Handle(store.Get(""), kv)
	a.Handle(store.Del(""), kv)
	a.HandleHTTP("/{key}", kv)

	bh.Start()
}
示例#2
0
文件: bench.go 项目: jyzhe/beehive
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	if *quiet {
		log.SetOutput(ioutil.Discard)
	}

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	hive := bh.NewHive()
	os.RemoveAll(hive.Config().StatePath)
	app := hive.NewApp("kvstore", bh.Persistent(*replFactor))
	kvs := &store.KVStore{
		Hive:    hive,
		Buckets: uint64(*buckets),
	}
	app.Handle(store.Put{}, kvs)
	app.Handle(store.Get(""), kvs)
	go hive.Start()

	time.Sleep(4 * time.Minute)

	keys := make([]string, *numkeys)
	reqs := make([]interface{}, *numkeys)
	val := "val"
	for i, _ := range keys {
		keys[i] = fmt.Sprintf("%dkeys%d", i, i)
		if *get {
			reqs[i] = store.Get(keys[i])
		} else {
			reqs[i] = store.Put{Key: keys[i], Val: val}
		}
	}

	for _, k := range keys {
		hive.Emit(store.Put{Key: k, Val: val})
		hive.Sync(context.Background(), store.Get(k))
	}

	ts := make([]time.Duration, *rounds)
	for i := 0; i < *rounds; i++ {
		start := time.Now()
		for j := 0; j < *tries; j++ {
			for _, r := range reqs {
				hive.Emit(r)
			}
		}
		for _, k := range keys {
			hive.Sync(context.Background(), store.Get(k))
		}
		ts[i] = time.Since(start)
	}

	hive.Stop()

	f, err := os.Create(*output)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	w := bufio.NewWriter(f)
	for _, t := range ts {
		fmt.Fprintf(w, "%v\n", uint64(t))
	}
	w.Flush()
}