Example #1
0
// Connect to the database, and initial setup
func connectToDatabase(host string, port int) {
	var err error

	// connect to the db
	if db, err = as.NewClient(host, port); err != nil {
		panic(err)
	}

	readPolicy = as.NewPolicy()
	writePolicy = as.NewWritePolicy(0, 0)
	scanPolicy = as.NewScanPolicy()

	// index on offer_id of bids, so we can find bids on a given offer
	if _, err := db.CreateIndex(writePolicy, "test", BIDS, "idx:br:1", "offer_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on broker_id of bids, so we can find bids by a particular broker
	if _, err := db.CreateIndex(writePolicy, "test", BIDS, "idx:br:2", "broker_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on broker_id of offers, so we can find offers by a particular broker
	if _, err := db.CreateIndex(writePolicy, "test", OFFERS, "idx:br:3", "broker_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on ticker of prices
	if _, err := db.CreateIndex(writePolicy, "test", PRICES, "idx:br:4", "ticker", as.STRING); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

}
func runExample(client *as.Client) {
	log.Printf("Scan parallel: namespace=" + *shared.Namespace + " set=" + *shared.Set)
	recordCount := 0
	begin := time.Now()
	policy := as.NewScanPolicy()
	recordset, err := client.ScanAll(policy, *shared.Namespace, *shared.Set)
	shared.PanicOnError(err)

L:
	for {
		select {
		case rec := <-recordset.Records:
			if rec == nil {
				break L
			}
			recordCount++

			if (recordCount % 10000) == 0 {
				log.Println("Records ", recordCount)
			}
		case err := <-recordset.Errors:
			// if there was an error, stop
			shared.PanicOnError(err)
		}
	}

	end := time.Now()
	seconds := float64(end.Sub(begin)) / float64(time.Second)
	log.Println("Total records returned: ", recordCount)
	log.Println("Elapsed time: ", seconds, " seconds")
	performance := shared.Round(float64(recordCount)/float64(seconds), 0.5, 0)
	log.Println("Records/second: ", performance)
}
Example #3
0
func runExample(client *as.Client) {
	log.Println("Scan series: namespace=", *shared.Namespace, " set=", *shared.Set)

	// Use low scan priority.  This will take more time, but it will reduce
	// the load on the server.
	policy := as.NewScanPolicy()
	policy.MaxRetries = 1
	policy.Priority = as.LOW

	nodeList := client.GetNodes()
	begin := time.Now()

	for _, node := range nodeList {
		log.Println("Scan node ", node.GetName())
		recordset, err := client.ScanNode(policy, node, *shared.Namespace, *shared.Set)
		shared.PanicOnError(err)

	L:
		for {
			select {
			case rec := <-recordset.Records:
				if rec == nil {
					break L
				}
				metrics, exists := setMap[rec.Key.SetName()]

				if !exists {
					metrics = Metrics{}
				}
				metrics.count++
				metrics.total++
				setMap[rec.Key.SetName()] = metrics

			case err := <-recordset.Errors:
				// if there was an error, stop
				shared.PanicOnError(err)
			}
		}

		for k, v := range setMap {
			log.Println("Node ", node, " set ", k, " count: ", v.count)
			v.count = 0
		}
	}

	end := time.Now()
	seconds := float64(end.Sub(begin)) / float64(time.Second)
	log.Println("Elapsed time: ", seconds, " seconds")

	total := 0

	for k, v := range setMap {
		log.Println("Total set ", k, " count: ", v.total)
		total += v.total
	}
	log.Println("Grand total: ", total)
	performance := shared.Round(float64(total)/seconds, 0.5, 0)
	log.Println("Records/second: ", performance)
}