Created
February 4, 2018 21:48
-
-
Save bcotton/c76a9efc394d442b7d3689f8a8b7e2ca to your computer and use it in GitHub Desktop.
Testing range queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dep init | |
// go build && ./bigtable-testing -project <project_id> -cluster cortex -tbl cortex | |
package main | |
import ( | |
"flag" | |
"log" | |
"strings" | |
"time" | |
"cloud.google.com/go/bigtable" | |
"golang.org/x/net/context" | |
) | |
var ( | |
project = flag.String("project", "", "gcp project") | |
cluster = flag.String("cluster", "", "bigtable cluster") | |
zone = flag.String("zone", "", "gcp zone") | |
tableName = flag.String("tbl", "", "table name") | |
hashValue = flag.String("hash-value", "0:d17565:ft_aggregation:ft_pod:disk_write_io_utilization_bytes_per_second:ft_target", "Starting hash value. Becomes the start of the row query") | |
rangeValueStart = flag.String("range-value-start", "02fd4a10", "Range value start. Concatenated with the hash-value with 000") | |
) | |
func queryWithRangeQuery(tbl *bigtable.Table, prefix string) int { | |
count := 0 | |
predicate := func(row bigtable.Row) bool { | |
count++ | |
return true | |
} | |
readOptions := []bigtable.ReadOption{ | |
bigtable.RowFilter(bigtable.FamilyFilter("f")), | |
} | |
start := time.Now() | |
ctx, cancel := context.WithCancel(context.Background()) | |
defer cancel() | |
prefixRange := bigtable.NewRange(prefix, *hashValue+separator+string('\xff')) | |
err := tbl.ReadRows(ctx, prefixRange, predicate, readOptions...) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Println("rangeQuery", prefixRange, count, time.Since(start)) | |
return count | |
} | |
func queryWithInfiniteRange(tbl *bigtable.Table, prefix string) int { | |
count := 0 | |
predicate := func(row bigtable.Row) bool { | |
if !strings.HasPrefix(row.Key(), *hashValue+separator) { | |
return false | |
} | |
count++ | |
return true | |
} | |
readOptions := []bigtable.ReadOption{ | |
bigtable.RowFilter(bigtable.FamilyFilter("f")), | |
} | |
start := time.Now() | |
ctx, cancel := context.WithCancel(context.Background()) | |
defer cancel() | |
err := tbl.ReadRows(ctx, bigtable.InfiniteRange(prefix), predicate, readOptions...) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Println("infiniteRange", prefix, count, time.Since(start)) | |
return count | |
} | |
const separator = "\000" | |
func main() { | |
flag.Parse() | |
btclient, err := bigtable.NewClient(context.Background(), *project, *cluster) | |
if err != nil { | |
log.Fatal(err) | |
} | |
tbl := btclient.Open(*tableName) | |
// validating connection | |
_, err = tbl.ReadRow(context.Background(), "fakequery") | |
if err != nil { | |
log.Fatal(err) | |
} | |
rangeQueryCount := queryWithRangeQuery(tbl, *hashValue+separator+*rangeValueStart+separator) | |
infiniteRangeCount := queryWithInfiniteRange(tbl, *hashValue+separator+*rangeValueStart+separator) | |
log.Printf("rangeQueryCount %v", rangeQueryCount) | |
log.Printf("infiniteRangeCount %v", infiniteRangeCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment