示例#1
0
func main() {

	flag.Parse()

	http.HandleFunc("/random", randDocument) // set router
	http.HandleFunc("/million", million)
	http.HandleFunc("/millionstr", millionstr)
	http.HandleFunc("/ffmillion", ffmillion)
	http.HandleFunc("/bufmillion", bufmillion)
	http.HandleFunc("/workmillion", workmillion)

	runtime.GOMAXPROCS(runtime.NumCPU())
	// start the thread pool
	dispatcher := NewDispatcher()
	dispatcher.Run()

	docMap := fetch.FetchDocs(*server, *bucket)
	if len(docMap) == 0 {
		log.Fatalf("Failed to fetch documents")
	}

	docs = &documents{docMap: docMap,
		docList:   make([]string, 0, len(docMap)),
		number:    len(docMap),
		docMapStr: make(map[string]string)}

	for dName, value := range docs.docMap {
		docs.docList = append(docs.docList, dName)
		item, _ := json.Marshal(value)
		docs.docMapStr[dName] = string(item)
	}

	err := http.ListenAndServe(":9090", nil) // set listen port
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
示例#2
0
文件: main.go 项目: maniktaneja/perf
func main() {
	flag.Parse()

	runtime.GOMAXPROCS(*threads)

	var client cbclient

	if *engine == "gocb" {
		client = newGoCbClient(*serverURL, *bucketName)
	} else {
		client = newGoCouchbaseClient(*serverURL, *bucketName)
	}

	start := time.Now()
	if *set == true {
		jsonDocs := fetch.FetchDocs(*serverURL, "beer-sample")
		if len(jsonDocs) == 0 {
			log.Fatalf("Fetched 0 docs ")
		}
		for i := 0; i < *threads; i++ {
			go client.doSetOps(*documents / *threads, i*(*documents / *threads), jsonDocs)
			wg.Add(1)
		}
	} else {
		for i := 0; i < *threads; i++ {
			go client.doBulkGetOps(*documents / *threads, *quantum, i*(*documents / *threads))
			wg.Add(1)
		}
	}

	wg.Wait()

	finish := time.Now().Sub(start)
	fmt.Printf("**** Did %d ops in %s. Ops/sec %d\n",
		*documents, finish.String(), int(float64(*documents)/finish.Seconds()))

}