Exemple #1
0
func PrintStore(s *Store, nKeys int64, p Partitioner) {
	for i := int64(0); i < nKeys; i++ {
		k := Key(i)
		partNum := p.GetPartition(k)
		r := s.GetRecord(k, partNum)
		if r == nil {
			clog.Error("Error No Key")
		}
		clog.Info("Key %v: %v", k, r.Value())
	}
}
func PrintPartition(s *Store, nKeys int64, p Partitioner, partNum int) {
	for i := int64(0); i < nKeys; i++ {
		k := Key(i)
		if p.GetPartition(k) != partNum {
			continue
		}
		r := s.GetRecord(k, partNum)
		if r == nil {
			clog.Error("Error No Key")
		}
		clog.Info("Key %v: %v", r.GetKey(), r.Value())
	}
}
Exemple #3
0
func main() {
	flag.Parse()

	// set max cores used, number of clients and number of workers
	runtime.GOMAXPROCS(*testbed.NumPart)
	clients := *testbed.NumPart
	nworkers := *testbed.NumPart

	if *contention < 1 {
		clog.Error("Contention factor should be between no less than 1")
	}

	clog.Info("Number of clients %v, Number of workers %v \n", clients, nworkers)
	if *testbed.SysType == testbed.PARTITION {
		clog.Info("Using Partition-based CC\n")
	} else if *testbed.SysType == testbed.OCC {
		if *testbed.PhyPart {
			clog.Info("Using OCC with partition\n")
		} else {
			clog.Info("Using OCC\n")
		}
	} else {
		clog.Error("Not supported type %v CC\n", *testbed.SysType)
	}

	tt, dt := getTxn(*txntype)

	// create store
	s := testbed.NewStore()
	var nParts int
	var hp testbed.Partitioner = nil
	var pKeysArray []int64
	var value interface{}

	if *testbed.SysType == testbed.PARTITION || *testbed.PhyPart {
		nParts = *testbed.NumPart
		pKeysArray = make([]int64, nParts)

		hp = &testbed.HashPartitioner{
			NParts: int64(nParts),
			NKeys:  int64(*nKeys),
		}

		var partNum int
		for i := int64(0); i < *nKeys; i++ {
			k := testbed.Key(i)
			partNum = hp.GetPartition(k)
			pKeysArray[partNum]++
			if dt == testbed.SINGLEINT {
				value = int64(0)
			} else if dt == testbed.STRINGLIST {
				value = testbed.GenStringList()
			}
			s.CreateKV(k, value, dt, partNum)
		}

	} else {
		nParts = 1
		for i := int64(0); i < *nKeys; i++ {
			k := testbed.Key(i)
			if dt == testbed.SINGLEINT {
				value = int64(0)
			} else if dt == testbed.STRINGLIST {
				value = testbed.GenStringList()
			}
			s.CreateKV(k, value, dt, 0)
		}
	}

	generators := make([]*testbed.TxnGen, nworkers)

	for i := 0; i < nworkers; i++ {
		p := &testbed.HashPartitioner{
			NParts: int64(nParts),
			NKeys:  int64(*nKeys),
		}
		zk := testbed.NewZipfKey(i, *nKeys, nParts, pKeysArray, *contention, p)
		generators[i] = testbed.NewTxnGen(i, tt, *rr, *txnlen, *mp, zk)
	}

	coord := testbed.NewCoordinator(nworkers, s)

	clog.Info("Done with Initialization")

	var wg sync.WaitGroup
	for i := 0; i < clients; i++ {
		wg.Add(1)
		go func(n int) {
			//var txn int64
			//var count int
			w := coord.Workers[n]
			end_time := time.Now().Add(time.Duration(*nsec) * time.Second)
			for {
				tm := time.Now()
				if !end_time.After(tm) {
					break
				}

				q := generators[n].GenOneQuery()

				//q.DoNothing()
				w.NGen += time.Since(tm)
				tm = time.Now()
				for j := 0; j < TRIAL; j++ {

					_, err := w.One(q)

					if err == nil {
						break
					} else if err == testbed.ENOKEY {
						clog.Error("No Key Error")
					} else if err != testbed.EABORT {
						clog.Error("Not Support Error Type %v", err)
					}
				}
				//_, err := w.One(q)
				w.NExecute += time.Since(tm)
				/*if err == testbed.ENOKEY {
					clog.Error("No Key Error")
					break
				}*/
				//txn++
			}
			//clog.Info("Worker %d issues %d transactions\n", n, txn)
			wg.Done()
		}(i)
	}
	wg.Wait()

	f, err := os.OpenFile(*out, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil {
		clog.Error("Open File Error %s\n", err.Error())
	}
	defer f.Close()
	coord.PrintStats(f)

	if *benchStat != "" {
		bs, err := os.OpenFile(*benchStat, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
		if err != nil {
			clog.Error("Open File Error %s\n", err.Error())
		}
		defer bs.Close()

		//bs.WriteString(fmt.Sprintf("%v\t%v\n", *testbed.CrossPercent, coord.NStats[testbed.NTXN]-coord.NStats[testbed.NABORTS]))
		bs.WriteString(fmt.Sprintf("%.f\n", float64(coord.NStats[testbed.NTXN]-coord.NStats[testbed.NABORTS])/coord.NExecute.Seconds()))
	}

}