Add ability to send in random strings

pull/174/head
Paul Dix 2014-01-09 16:05:12 -05:00 committed by John Shahid
parent 97d5b51d1f
commit ae7305f1c6
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main
import (
crand "crypto/rand"
"flag"
"fmt"
"github.com/BurntSushi/toml"
@ -330,7 +331,11 @@ func (self *BenchmarkHarness) runLoad(seriesNames []string, columns []string, lo
point = append(point, rand.Float64())
}
for _, col := range loadDef.StringColumns {
point = append(point, col.Values[rand.Intn(len(col.Values))])
if col.RandomLength != 0 {
point = append(point, self.randomString(col.RandomLength))
} else {
point = append(point, col.Values[rand.Intn(len(col.Values))])
}
}
s.Points[pointCount] = point
@ -344,6 +349,16 @@ func (self *BenchmarkHarness) runLoad(seriesNames []string, columns []string, lo
}
}
func (self *BenchmarkHarness) randomString(length int) string {
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, length)
crand.Read(bytes)
for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
return string(bytes)
}
func (self *BenchmarkHarness) runQuery(loadDef *loadDefinition, seriesNames []string, q *query) {
sleepTime, err := time.ParseDuration(q.PerformEvery)
if err != nil {