예제 #1
0
파일: load.go 프로젝트: pinterb/couchloader
func CouchbaseBucket(url, bucket, password string) (cb *gocb.Bucket, err error) {
	if c, err := gocb.Connect(url); err == nil {
		if b, err := c.OpenBucket(bucket, password); err == nil {
			return b, nil
		}
	}
	return nil, err
}
예제 #2
0
func newDatastore() (ds *couchbaseDatastore, err error) {
	url, bucket, pass := parseFlag()

	if c, err := gocb.Connect(url); err == nil {
		if b, err := c.OpenBucket(bucket, pass); err == nil {
			return (*couchbaseDatastore)(b), nil
		}
	}
	return nil, err
}
예제 #3
0
func main() {

	gocbcore.SetLogger(gocbcore.DefaultStdOutLogger())

	cluster, _ := gocb.Connect("couchbase://52.17.36.153")
	bucket, _ := cluster.OpenBucket("ryanair", "")

	router := router.NewRouter(bucket)
	log.Fatal(http.ListenAndServe(":8080", router))
}
func main() {
	gocbcore.SetLogger(gocbcore.DefaultStdOutLogger())
	runtime.GOMAXPROCS(runtime.NumCPU())
	cluster, _ = gocb.Connect("http://172.31.31.191")
	bucket, _ = cluster.OpenBucket("default", "")
	bucket.Upsert("test", 0, 100)
	bucket.Upsert("total_votes", 0, 0)
	ch = make(chan Event, 1000)
	time.AfterFunc(1*time.Second, func() {
		for i := 1; i < 72; i++ {
			fmt.Println("starting worker %d", i)
			go worker(ch)
		}
	})
	http.HandleFunc("/vote", voteHandler)
	http.HandleFunc("/loaderio-35df9c4fffde902e3b0e3e0115816d82.html", validationHandler)
	http.ListenAndServe(":80", nil)
}
예제 #5
0
func main() {
	cluster, err := gocb.Connect("couchbase://127.0.0.1")

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	bucket, err = cluster.OpenBucket("assets", "")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	http.HandleFunc("/api/assets", assetHandler)

	fmt.Printf("Starting server on :9980\n")
	http.ListenAndServe(":9990", nil)

}
예제 #6
0
func main() {
	cluster, _ := gocb.Connect("couchbase://127.0.0.1")
	bucket, _ = cluster.OpenBucket("beer-sample", "")

	http.HandleFunc("/", welcomeHandler)
	http.HandleFunc("/beers", beerIndexHandler)
	http.HandleFunc("/beers/search", beerSearchHandler)
	http.HandleFunc("/beers/show/", beerShowHandler)
	http.HandleFunc("/beers/create", beerCreateHandler)
	http.HandleFunc("/beers/edit/", beerEditHandler)
	http.HandleFunc("/beers/delete/", removeHandler)
	http.HandleFunc("/breweries", brewIndexHandler)
	http.HandleFunc("/breweries/search", brewSearchHandler)
	http.HandleFunc("/breweries/show/", brewShowHandler)
	http.HandleFunc("/breweries/delete/", removeHandler)

	http.Handle("/css/", http.FileServer(http.Dir("static/")))
	http.Handle("/js/", http.FileServer(http.Dir("static/")))

	fmt.Printf("Starting server on :9980\n")
	http.ListenAndServe(":9980", nil)
}
예제 #7
0
func main() {
	runtime.GOMAXPROCS(2)

	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}

		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	cluster, err := gocb.Connect(*spec)
	fmt.Printf("OpenCluster: %v, %v\n", cluster, err)

	bucket, err := cluster.OpenBucket(*bucket, *password)
	fmt.Printf("OpenBucket: %v, %v\n", bucket, err)

	minItemSize := int(*minsize)
	maxItemSize := int(*maxsize)
	numItems := int(*numitems)
	numWorkers := int(*numconcur)
	pctSetOps := int(*setpct)
	numConcur := int(*numconcur)
	totalOps := int(*numops)
	opsPerWorker := totalOps / numConcur

	if !*nopop {
		signal := make(chan bool, 1)
		for i := 0; i < numItems; i++ {
			go func(i int) {
				itemKey := *prefix + strconv.Itoa(i)
				itemSize := rand.Intn(maxItemSize-minItemSize) + minItemSize
				item := makeItem(itemSize)
				_, err := bucket.Upsert(itemKey, item, 0)
				if err != nil {
					log.Fatal("Failed during initial insertion of items.")
				}
				signal <- true
			}(i)
		}
		for i := 0; i < numItems; i++ {
			<-signal
		}
		fmt.Printf("Completed initial insertion.\n")
	}

	signal := make(chan workerResults, numWorkers)
	workerThread := func(workerId int) {
		results := workerResults{
			Id: workerId,
		}

		rng := rand.New(rand.NewSource(int64(workerId)))

		for i := 0; i < opsPerWorker; i++ {
			itemKey := *prefix + strconv.Itoa(rng.Intn(numItems))

			if rng.Intn(100) < pctSetOps {
				// Do a Set
				itemSize := rng.Intn(maxItemSize-minItemSize) + minItemSize
				item := makeItem(itemSize)

				opSTime := time.Now()
				_, err := bucket.Upsert(itemKey, item, 0)
				opETime := time.Now()

				if err != nil {
					results.SetRes.Err++
				}

				opDTime := opETime.Sub(opSTime)
				results.SetRes.AddItem(opDTime)
			} else {
				// Do a Get
				var item testItem

				opSTime := time.Now()
				_, err := bucket.Get(itemKey, &item)
				opETime := time.Now()

				if err != nil {
					results.GetRes.Err++
				}

				opDTime := opETime.Sub(opSTime)
				results.GetRes.AddItem(opDTime)
			}
		}

		signal <- results
	}

	sTime := time.Now()

	// Start all the workers
	for i := 0; i < numWorkers; i++ {
		go workerThread(i)
	}

	// Join all the workers
	resultTotals := &workerResults{}
	for i := 0; i < numWorkers; i++ {
		result := <-signal
		resultTotals.Add(result)

		//fmt.Printf("Worker %d finished with %d:%d sets and %d:%d gets (success:error)\n", result.Id,
		//	result.SetOkCount, result.SetErrCount, result.GetOkCount, result.GetErrCount)
	}

	eTime := time.Now()
	dTime := eTime.Sub(sTime)
	opsPerSec := float64(totalOps) / (float64(dTime) / float64(time.Second))

	fmt.Printf("%d concurrent of %d ops (%d total) took %s (%f ops/s)\n", numConcur, opsPerWorker, totalOps, dTime, opsPerSec)
	resultTotals.Print()

	return
}