Skip to content

Commit

Permalink
add option not to measure latency
Browse files Browse the repository at this point in the history
  • Loading branch information
pdziepak committed Aug 15, 2017
1 parent 398e94e commit 23ab7c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
37 changes: 26 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var startTime time.Time

var stopAll uint32

var measureLatency bool

func PrepareDatabase(session *gocql.Session, replicationFactor int) {
request := fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : %d }", keyspaceName, replicationFactor)
err := session.Query(request).Exec()
Expand Down Expand Up @@ -107,10 +109,14 @@ func PrintPartialResult(result *MergedResult) {
if errorRecordingLatency {
latencyError = "latency measurement error"
}
fmt.Println(result.Time, "\t", result.Operations, "\t", result.ClusteringRows, "\t", result.Errors,
"\t", time.Duration(result.Latency.Max()), "\t", time.Duration(result.Latency.ValueAtQuantile(99.9)), "\t", time.Duration(result.Latency.ValueAtQuantile(99)),
"\t", time.Duration(result.Latency.ValueAtQuantile(95)), "\t", time.Duration(result.Latency.ValueAtQuantile(90)), "\t", time.Duration(result.Latency.ValueAtQuantile(50)),
latencyError)
if measureLatency {
fmt.Println(result.Time, "\t", result.Operations, "\t", result.ClusteringRows, "\t", result.Errors,
"\t", time.Duration(result.Latency.Max()), "\t", time.Duration(result.Latency.ValueAtQuantile(99.9)), "\t", time.Duration(result.Latency.ValueAtQuantile(99)),
"\t", time.Duration(result.Latency.ValueAtQuantile(95)), "\t", time.Duration(result.Latency.ValueAtQuantile(90)), "\t", time.Duration(result.Latency.ValueAtQuantile(50)),
latencyError)
} else {
fmt.Println(result.Time, "\t", result.Operations, "\t", result.ClusteringRows, "\t", result.Errors)
}
}

func toInt(value bool) int {
Expand Down Expand Up @@ -163,6 +169,8 @@ func main() {

flag.Int64Var(&partitionOffset, "partition-offset", 0, "start of the partition range (only for sequential workload)")

flag.BoolVar(&measureLatency, "measure-latency", true, "measure request latency")

var startTimestamp int64
flag.Int64Var(&writeRate, "write-rate", 0, "rate of writes (relevant only for time series reads)")
flag.Int64Var(&startTimestamp, "start-timestamp", 0, "start timestamp of the write load (relevant only for time series reads)")
Expand Down Expand Up @@ -303,7 +311,12 @@ func main() {
startTime = time.Now()
}

fmt.Println("\ntime\t\toperations/s\trows/s\t\terrors\tmax\t\t99.9th\t\t99th\t\t95th\t\t90th\t\tmedian")
if measureLatency {
fmt.Println("\ntime\t\toperations/s\trows/s\t\terrors\tmax\t\t99.9th\t\t99th\t\t95th\t\t90th\t\tmedian")
} else {
fmt.Println("\ntime\t\toperations/s\trows/s\t\terrors")
}

result := RunConcurrently(maximumRate, func(i int, resultChannel chan Result, rateLimiter RateLimiter) {
GetMode(mode)(session, resultChannel, GetWorkload(workload, i, partitionOffset, mode, writeRate, distribution), rateLimiter)
})
Expand All @@ -320,10 +333,12 @@ func main() {
if errorRecordingLatency {
fmt.Println("Latency measurements may be inaccurate")
}
fmt.Println("Latency:\n max:\t\t", time.Duration(result.Latency.Max()),
"\n 99.9th:\t", time.Duration(result.Latency.ValueAtQuantile(99.9)),
"\n 99th:\t\t", time.Duration(result.Latency.ValueAtQuantile(99)),
"\n 95th:\t\t", time.Duration(result.Latency.ValueAtQuantile(95)),
"\n 90th:\t\t", time.Duration(result.Latency.ValueAtQuantile(90)),
"\n median:\t", time.Duration(result.Latency.ValueAtQuantile(50)))
if measureLatency {
fmt.Println("Latency:\n max:\t\t", time.Duration(result.Latency.Max()),
"\n 99.9th:\t", time.Duration(result.Latency.ValueAtQuantile(99.9)),
"\n 99th:\t\t", time.Duration(result.Latency.ValueAtQuantile(99)),
"\n 95th:\t\t", time.Duration(result.Latency.ValueAtQuantile(95)),
"\n 90th:\t\t", time.Duration(result.Latency.ValueAtQuantile(90)),
"\n median:\t", time.Duration(result.Latency.ValueAtQuantile(50)))
}
}
15 changes: 12 additions & 3 deletions modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ func (mr *MergedResult) AddResult(result Result) {
mr.OperationsPerSecond += float64(result.Operations) / result.ElapsedTime.Seconds()
mr.ClusteringRowsPerSecond += float64(result.ClusteringRows) / result.ElapsedTime.Seconds()
mr.Errors += result.Errors
dropped := mr.Latency.Merge(result.Latency)
if dropped > 0 {
log.Print("dropped: ", dropped)
if measureLatency {
dropped := mr.Latency.Merge(result.Latency)
if dropped > 0 {
log.Print("dropped: ", dropped)
}
}
}

func NewHistogram() *hdrhistogram.Histogram {
if !measureLatency {
return nil
}
return hdrhistogram.New(time.Microsecond.Nanoseconds()*50, (timeout + timeout*2).Nanoseconds(), 3)
}

Expand Down Expand Up @@ -200,6 +205,10 @@ func (rb *ResultBuilder) ResetPartialResult() {
}

func (rb *ResultBuilder) RecordLatency(latency time.Duration, rateLimiter RateLimiter) error {
if !measureLatency {
return nil
}

err := rb.FullResult.Latency.RecordCorrectedValue(latency.Nanoseconds(), rateLimiter.ExpectedInterval())
if err != nil {
return err
Expand Down

0 comments on commit 23ab7c8

Please sign in to comment.