예제 #1
0
func (s SysbenchUpdateInfo) Do(c chan<- interface{}) {
	db := s.Session.DB(s.Dbname)
	collectionIndex := s.RandSource.Int31n(int32(s.NumCollections))
	coll := db.C(mongotools.GetCollectionString(s.Collname, int(collectionIndex)))
	var sbresult SysbenchUpdateResult

	var i uint

	//db.sbtest8.update({_id: 5523412}, {$set: {c: "hello there"}}, false, false)
	// have each thread do 50 updates before sending results
	for i = 0; i < 50; i++ {
		randID := s.RandSource.Int63n(s.MaxID)
		var err error
		if s.doFindAndModify {
			change := mgo.Change{
				Update:    bson.M{"$inc": bson.M{"d": 1}},
				ReturnNew: true,
			}
			var info *mgo.ChangeInfo
			var doc bson.M
			info, err = coll.Find(bson.M{"_id": randID}).Apply(change, &doc)
			info = info // to make the compiler shut up about unused variable info.
		} else {
			err = coll.Update(bson.M{"_id": randID}, bson.M{"$inc": bson.M{"d": 1}})
		}
		if err != nil {
			// we got an error
			sbresult.NumErrors++
		}

		// send result over channel
		sbresult.NumUpdates++
	}
	c <- sbresult
}
예제 #2
0
func main() {
	// needed for making/accessing collections:
	host := flag.String("host", "localhost", "host:port string of database to connect to")
	dbname := "partitionStress"
	collname := "partitionStress"

	flag.Parse()

	session, err := mgo.Dial(*host)
	if err != nil {
		log.Fatal("Error connecting to ", *host, ": ", err)
	}
	// so we are not in fire and forget
	session.SetSafe(&mgo.Safe{})
	defer session.Close()

	indexes := make([]mgo.Index, 3)
	indexes[0] = mgo.Index{Key: []string{"pr", "cid"}}
	indexes[1] = mgo.Index{Key: []string{"crid", "pr", "cid"}}
	indexes[2] = mgo.Index{Key: []string{"pr", "ts", "cid"}}

	mongotools.MakeCollections(collname, dbname, 1, session, indexes)
	// at this point we have created the collection, now run the benchmark
	res := new(iibench.Result)
	numWriters := 8
	numQueryThreads := 16
	workers := make([]benchmark.WorkInfo, 0, numWriters+numQueryThreads)
	currCollectionString := mongotools.GetCollectionString(collname, 0)
	for i := 0; i < numWriters; i++ {
		copiedSession := session.Copy()
		defer copiedSession.Close()
		var gen = iibench.NewDocGenerator()
		gen.CharFieldLength = 100
		gen.NumCharFields = 0
		workers = append(workers, mongotools.NewInsertWork(gen, copiedSession.DB(dbname).C(currCollectionString), 0))
	}
	for i := 0; i < numQueryThreads; i++ {
		copiedSession := session.Copy()
		defer copiedSession.Close()
		workers = append(workers, iibench.NewQueryWork(copiedSession, dbname, currCollectionString))
	}
	{
		copiedSession := session.Copy()
		defer copiedSession.Close()
		var addPartitionItem = partition_stress.AddPartitionWork{copiedSession.DB(dbname), currCollectionString, time.Hour}
		workers = append(workers, benchmark.WorkInfo{addPartitionItem, 1, 1, 0})
	}
	{
		copiedSession := session.Copy()
		defer copiedSession.Close()
		var dropPartitionItem = partition_stress.DropPartitionWork{copiedSession.DB(dbname), currCollectionString, 7 * time.Hour}
		workers = append(workers, benchmark.WorkInfo{dropPartitionItem, 1, 1, 0})
	}
	// have this go for a looooooong time
	benchmark.Run(res, workers, time.Duration(1<<32)*time.Second)
}
예제 #3
0
func main() {
	flag.Parse()

	if *numInsertsPerThread > 0 && (*numQueryThreads > 0 || *numSeconds > 0) {
		log.Fatal("Invalid values for numInsertsPerThread: ", *numInsertsPerThread, ", numQueryThreads: ", *numQueryThreads, ", numSeconds: ", *numSeconds)
	}

	session, err := mgo.Dial(*host)
	if err != nil {
		log.Fatal("Error connecting to ", *host, ": ", err)
	}
	// so we are not in fire and forget
	session.SetSafe(&mgo.Safe{})
	defer session.Close()

	indexes := make([]mgo.Index, 3)
	indexes[0] = mgo.Index{Key: []string{"pr", "cid"}}
	indexes[1] = mgo.Index{Key: []string{"crid", "pr", "cid"}}
	indexes[2] = mgo.Index{Key: []string{"pr", "ts", "cid"}}

	mongotools.MakeCollections(*collname, *dbname, *numCollections, session, indexes)
	// at this point we have created the collection, now run the benchmark
	res := new(iibench.Result)
	workers := make([]benchmark.WorkInfo, 0, *numWriters+*numQueryThreads)
	for i := 0; i < *numWriters; i++ {
		copiedSession := session.Copy()
		defer copiedSession.Close()
		var gen = iibench.NewDocGenerator()
		currCollectionString := mongotools.GetCollectionString(*collname, i%*numCollections)
		workers = append(workers, mongotools.NewInsertWork(gen, copiedSession.DB(*dbname).C(currCollectionString), *numInsertsPerThread))
	}
	for i := 0; i < *numQueryThreads; i++ {
		currCollectionString := mongotools.GetCollectionString(*collname, i%*numCollections)
		copiedSession := session.Copy()
		defer copiedSession.Close()
		workers = append(workers, iibench.NewQueryWork(copiedSession, *dbname, currCollectionString))
	}
	benchmark.Run(res, workers, time.Duration(*numSeconds)*time.Second)
}
예제 #4
0
func main() {
	flag.Parse()
	if *numWriters > *numCollections {
		log.Fatal("numWriters should not be greater than numCollections")
	}

	session, err := mgo.Dial(*host)
	if err != nil {
		log.Fatal("Error connecting to ", *host, ": ", err)
	}
	// so we are not in fire and forget
	session.SetSafe(&mgo.Safe{})
	defer session.Close()

	indexes := make([]mgo.Index, 1)
	indexes[0] = mgo.Index{Key: []string{"k"}}

	mongotools.MakeCollections(*collname, *dbname, *numCollections, session, indexes)
	// at this point we have created the collection, now run the benchmark
	res := new(iibench.Result)
	workers := make([]benchmark.WorkInfo, 0, *numWriters)

	var writers []SysbenchWriter = make([]SysbenchWriter, *numWriters)
	for i := 0; i < *numCollections; i++ {
		copiedSession := session.Copy()
		defer copiedSession.Close()
		currCollectionString := mongotools.GetCollectionString(*collname, i)
		var gen *SysbenchDocGenerator = new(SysbenchDocGenerator)
		gen.RandSource = rand.New(rand.NewSource(time.Now().UnixNano()))
		var curr benchmark.WorkInfo = mongotools.NewInsertWork(gen, copiedSession.DB(*dbname).C(currCollectionString), *numInsertsPerCollection)
		writers[i%*numWriters].writers = append(writers[i%*numWriters].writers, curr)
	}
	for i := 0; i < *numWriters; i++ {
		var curr benchmark.WorkInfo = benchmark.WorkInfo{Work: writers[i]}
		curr.MaxOps = writers[i].writers[0].MaxOps
		workers = append(workers, curr)
	}
	benchmark.Run(res, workers, 0)
}
예제 #5
0
func (s SysbenchTransaction) Do(c chan<- interface{}) {
	db := s.Session.DB(s.Dbname)
	collectionIndex := s.RandSource.Int31n(int32(s.NumCollections))
	coll := db.C(mongotools.GetCollectionString(s.Collname, int(collectionIndex)))
	var sbresult SysbenchResult

	txn := mongotools.Transaction{DB: db}
	if err := txn.Begin(); err != nil {
		sbresult.NumErrors++
	}
	defer txn.Close()

	var i uint
	for i = 0; i < s.Info.oltpPointSelects; i++ {
		// db.sbtest8.find({_id: 554312}, {c: 1, _id: 0})
		filter := bson.M{"_id": s.RandSource.Int63n(int64(s.MaxID))}
		projection := bson.M{"c": 1}
		runQuery(filter, projection, coll)
	}
	for i = 0; i < s.Info.oltpSimpleRanges; i++ {
		//db.sbtest8.find({_id: {$gte: 5523412, $lte: 5523512}}, {c: 1, _id: 0})
		startID := s.RandSource.Int63n(s.MaxID)
		endID := startID + int64(s.Info.oltpRangeSize)
		filter := bson.M{"_id": bson.M{"$gte": startID, "$lt": endID}}
		projection := bson.M{"c": 1}
		runQuery(filter, projection, coll)
	}
	for i = 0; i < s.Info.oltpSumRanges; i++ {
		//db.sbtest8.aggregate([ {$match: {_id: {$gt: 5523412, $lt: 5523512}}}, { $group: { _id: null, total: { $sum: "$k"}} } ])
		startID := s.RandSource.Int63n(s.MaxID)
		endID := startID + int64(s.Info.oltpRangeSize)
		firstPipe := bson.M{"$match": bson.M{"_id": bson.M{"$gt": startID, "$lt": endID}}}
		secondPipe := bson.M{"$group": bson.M{"_id": nil, "total": bson.M{"$sum": "$k"}}} // is this $k correct?
		pipe := coll.Pipe([]bson.M{firstPipe, secondPipe})
		iter := pipe.Iter()
		var result bson.M
		for iter.Next(&result) {
		}
	}
	for i = 0; i < s.Info.oltpOrderRanges; i++ {
		//db.sbtest8.find({_id: {$gte: 5523412, $lte: 5523512}}, {c: 1, _id: 0}).sort({c: 1})
		startID := s.RandSource.Int63n(s.MaxID)
		endID := startID + int64(s.Info.oltpRangeSize)
		filter := bson.M{"_id": bson.M{"$gte": startID, "$lt": endID}}
		projection := bson.M{"c": 1}
		var result bson.M
		iter := coll.Find(filter).Select(projection).Sort("c").Iter()
		for iter.Next(&result) {
		}
	}
	for i = 0; i < s.Info.oltpDistinctRanges; i++ {
		//db.sbtest8.distinct("c",{_id: {$gt: 5523412, $lt: 5523512}}).sort()
		startID := s.RandSource.Int63n(s.MaxID)
		endID := startID + int64(s.Info.oltpRangeSize)
		filter := bson.M{"_id": bson.M{"$gte": startID, "$lt": endID}}
		var distinctResults []string
		err := coll.Find(filter).Distinct("c", &distinctResults)
		if err != nil {
			// we got an error
			sbresult.NumErrors++
		}
	}
	if !s.ReadOnly {
		for i = 0; i < s.Info.oltpIndexUpdates; i++ {
			//db.sbtest8.update({_id: 5523412}, {$inc: {k: 1}}, false, false)
			randID := s.RandSource.Int63n(s.MaxID)
			err := coll.Update(bson.M{"_id": randID}, bson.M{"$inc": bson.M{"k": 1}})
			if err != nil {
				// we got an error
				sbresult.NumErrors++
			}
		}
		for i = 0; i < s.Info.oltpNonIndexUpdates; i++ {
			//db.sbtest8.update({_id: 5523412}, {$set: {c: "hello there"}}, false, false)
			randID := s.RandSource.Int63n(s.MaxID)
			err := coll.Update(bson.M{"_id": randID}, bson.M{"$set": bson.M{"c": sysbench.CString(s.RandSource)}})
			if err != nil {
				// we got an error
				sbresult.NumErrors++
			}
		}
	}
	// remove an ID
	// re-insert the ID
	randID := s.RandSource.Int63n(s.MaxID)
	err := coll.Remove(bson.M{"_id": randID})
	if err != nil {
		// we got an error
		sbresult.NumErrors++
	}
	// TODO: re-insert the ID
	err = coll.Insert(sysbench.Doc{
		uint64(randID),
		s.RandSource.Int(),
		s.RandSource.Int(),
		sysbench.CString(s.RandSource),
		sysbench.PadString(s.RandSource)})
	if err != nil {
		// we got an error
		sbresult.NumErrors++
	} else {
		txn.Commit()
	}

	// send result over channel
	sbresult.NumTransactions++
	c <- sbresult
}