Skip to content

Commit

Permalink
add counter_read mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pdziepak committed Jul 11, 2017
1 parent 3d7fb42 commit 6fef8f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Finally, scylla-bench can send a request with an IN restriction (flag `-in-restr
SELECT * from %s.%s WHERE pk = ? AND ck IN (?, ...)
```

### Counter read mode (`-mode counter_read`)

Counter read mode works in exactly the same as regular read mode (with the same configuration flags available) except that it reads data from the counter table `scylla_bench.test_counters`.

### Workloads

The second very important part of scylla-bench configuration is the workload. While mode chooses what kind of requests are to be sent to the cluster the workload decides which partitions and rows should be the target of these requests.
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func GetMode(name string) func(session *gocql.Session, resultChannel chan Result
return DoCounterUpdates
case "read":
return DoReads
case "counter_read":
return DoCounterReads
default:
log.Fatal("unknown mode: ", name)
}
Expand Down Expand Up @@ -130,7 +132,7 @@ func main() {
var writeRate int64
var distribution string

flag.StringVar(&mode, "mode", "", "operating mode: write, read")
flag.StringVar(&mode, "mode", "", "operating mode: write, read, counter_update, counter_read")
flag.StringVar(&workload, "workload", "", "workload: sequential, uniform, timeseries")
flag.StringVar(&consistencyLevel, "consistency-level", "quorum", "consistency level")
flag.IntVar(&replicationFactor, "replication-factor", 1, "replication factor")
Expand Down Expand Up @@ -188,7 +190,7 @@ func main() {
}

readModeTweaks := toInt(inRestriction) + toInt(provideUpperBound) + toInt(noLowerBound)
if mode != "read" {
if mode != "read" && mode != "counter_read" {
if readModeTweaks != 0 {
log.Fatal("in-restriction, no-lower-bound and provide-uppder-bound flags make sense only in read mode")
}
Expand Down
26 changes: 20 additions & 6 deletions modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,27 @@ func DoCounterUpdates(session *gocql.Session, resultChannel chan Result, workloa
}

func DoReads(session *gocql.Session, resultChannel chan Result, workload WorkloadGenerator, rateLimiter RateLimiter) {
DoReadsFromTable(tableName, session, resultChannel, workload, rateLimiter)
}

func DoCounterReads(session *gocql.Session, resultChannel chan Result, workload WorkloadGenerator, rateLimiter RateLimiter) {
DoReadsFromTable(counterTableName, session, resultChannel, workload, rateLimiter)
}

func DoReadsFromTable(table string, session *gocql.Session, resultChannel chan Result, workload WorkloadGenerator, rateLimiter RateLimiter) {
var request string
if inRestriction {
arr := make([]string, rowsPerRequest)
for i := 0; i < rowsPerRequest; i++ {
arr[i] = "?"
}
request = fmt.Sprintf("SELECT * from %s.%s WHERE pk = ? AND ck IN (%s)", keyspaceName, tableName, strings.Join(arr, ", "))
request = fmt.Sprintf("SELECT * from %s.%s WHERE pk = ? AND ck IN (%s)", keyspaceName, table, strings.Join(arr, ", "))
} else if provideUpperBound {
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? AND ck >= ? AND ck < ?", keyspaceName, tableName)
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? AND ck >= ? AND ck < ?", keyspaceName, table)
} else if noLowerBound {
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? LIMIT %d", keyspaceName, tableName, rowsPerRequest)
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? LIMIT %d", keyspaceName, table, rowsPerRequest)
} else {
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? AND ck >= ? LIMIT %d", keyspaceName, tableName, rowsPerRequest)
request = fmt.Sprintf("SELECT * FROM %s.%s WHERE pk = ? AND ck >= ? LIMIT %d", keyspaceName, table, rowsPerRequest)
}
query := session.Query(request)

Expand Down Expand Up @@ -363,8 +371,14 @@ func DoReads(session *gocql.Session, resultChannel chan Result, workload Workloa

requestStart := time.Now()
iter := bound.Iter()
for iter.Scan(nil, nil, nil) {
rb.IncRows()
if table == tableName {
for iter.Scan(nil, nil, nil) {
rb.IncRows()
}
} else {
for iter.Scan(nil, nil, nil, nil, nil, nil, nil) {
rb.IncRows()
}
}
requestEnd := time.Now()

Expand Down

0 comments on commit 6fef8f2

Please sign in to comment.