Beispiel #1
0
func (state *State) MeasureLatency(database databases.Database,
	workload Workload, config Config, wg *sync.WaitGroup) {
	defer wg.Done()

	for state.Operations < config.Operations {
		if config.CreatePercentage > 0 {
			state.Operations++
			state.Records++
			key := workload.GenerateNewKey(state.Records)
			value := workload.GenerateValue(key, config.IndexableFields, config.ValueSize)
			t0 := time.Now()
			database.Create(key, value)
			t1 := time.Now()
			state.Latency["Create"].AddSample(summstat.Sample(t1.Sub(t0)))
		}
		if config.ReadPercentage > 0 {
			state.Operations++
			key := workload.GenerateExistingKey(state.Records)
			t0 := time.Now()
			database.Read(key)
			t1 := time.Now()
			state.Latency["Read"].AddSample(summstat.Sample(t1.Sub(t0)))
		}
		if config.UpdatePercentage > 0 {
			state.Operations++
			key := workload.GenerateExistingKey(state.Records)
			value := workload.GenerateValue(key, config.IndexableFields, config.ValueSize)
			t0 := time.Now()
			database.Update(key, value)
			t1 := time.Now()
			state.Latency["Update"].AddSample(summstat.Sample(t1.Sub(t0)))
		}
		if config.DeletePercentage > 0 {
			state.Operations++
			key := workload.GenerateKeyForRemoval()
			t0 := time.Now()
			database.Delete(key)
			t1 := time.Now()
			state.Latency["Delete"].AddSample(summstat.Sample(t1.Sub(t0)))
		}
		if config.QueryPercentage > 0 {
			state.Operations++
			fieldName, fieldValue, limit := workload.GenerateQuery(config.IndexableFields,
				state.Records)
			t0 := time.Now()
			database.Query(fieldName, fieldValue, limit)
			t1 := time.Now()
			state.Latency["Query"].AddSample(summstat.Sample(t1.Sub(t0)))
		}
		time.Sleep(time.Second)
	}
}
Beispiel #2
0
func main() {
	//	rand.Seed(int64(time.Now().Nanosecond()))
	r := make([]*stats.Stats, 4)
	for i := range r {
		r[i] = stats.NewStats()
		//		r[i].CreateBins(100, 0, 200)
	}
	const n = 100000
	for i := 0; i < n; i++ {
		cs := []*character{
			newCharacter(jemimaPaths),
			newCharacter(peterPaths),
			newCharacter(squirrelPaths),
			newCharacter(jeremyPaths),
		}
		for i, c := range cs {
			r[i].AddSample(stats.Sample(c.play()))
		}
	}
	for i, s := range r {
		fmt.Printf("%d. min %g max %g mean %.2g±%.2g median %g\n", i, s.Min(), s.Max(), s.Mean(), s.Stddev(), s.Median())
	}
}