Added az benchmark test

This commit is contained in:
tidwall 2018-11-11 07:35:31 -07:00
parent b2203fcb97
commit 090a05735f
2 changed files with 122 additions and 70 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,10 +8,13 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/tidwall/redbench" "github.com/tidwall/redbench"
"github.com/tidwall/redcon"
"github.com/tidwall/tile38/cmd/tile38-benchmark/az"
"github.com/tidwall/tile38/core" "github.com/tidwall/tile38/core"
) )
@ -280,8 +283,9 @@ func main() {
) )
} }
case "INTERSECTS", case "INTERSECTS",
"INTERSECTS-RECT", "INTERSECTS-RECT-1000", "INTERSECTS-RECT-10000", "INTERSECTS-RECT-100000", "INTERSECTS-BOUNDS", "INTERSECTS-BOUNDS-1000", "INTERSECTS-BOUNDS-10000", "INTERSECTS-BOUNDS-100000",
"INTERSECTS-CIRCLE", "INTERSECTS-CIRCLE-1000", "INTERSECTS-CIRCLE-10000", "INTERSECTS-CIRCLE-100000": "INTERSECTS-CIRCLE", "INTERSECTS-CIRCLE-1000", "INTERSECTS-CIRCLE-10000", "INTERSECTS-CIRCLE-100000",
"INTERSECTS-AZ":
if redis { if redis {
break break
} }
@ -368,6 +372,51 @@ func main() {
) )
} }
switch strings.ToUpper(strings.TrimSpace(test)) {
case "INTERSECTS", "INTERSECTS-AZ":
var mu sync.Mutex
var loaded bool
redbench.Bench("INTERSECTS (intersects-az limit 5)", addr, opts, func(conn net.Conn) bool {
func() {
mu.Lock()
defer mu.Unlock()
if loaded {
return
}
loaded = true
p := make([]byte, 0xFF)
conn.Write([]byte("GET keys:bench:geo az point\r\n"))
n, err := conn.Read(p)
if err != nil {
panic(err)
}
if string(p[:n]) != ":-1\r\n" {
return
}
args := []string{"SET", "key:bench:geo", "az", "object", az.JSON}
out := redcon.AppendArray(nil, len(args))
for _, arg := range args {
out = redcon.AppendBulkString(out, arg)
}
conn.Write(out)
n, err = conn.Read(p)
if err != nil {
panic(err)
}
if string(p[:n]) != "+OK\r\n" {
panic("expected OK")
}
}()
return prepFn(conn)
},
func(buf []byte) []byte {
args := []string{"INTERSECTS", "key:bench", "LIMIT", "5",
"COUNT", "GET", "key:bench:geo", "az"}
return redbench.AppendCommand(buf, args...)
},
)
}
case "WITHIN", case "WITHIN",
"WITHIN-RECT", "WITHIN-RECT-1000", "WITHIN-RECT-10000", "WITHIN-RECT-100000", "WITHIN-RECT", "WITHIN-RECT-1000", "WITHIN-RECT-10000", "WITHIN-RECT-100000",
"WITHIN-CIRCLE", "WITHIN-CIRCLE-1000", "WITHIN-CIRCLE-10000", "WITHIN-CIRCLE-100000": "WITHIN-CIRCLE", "WITHIN-CIRCLE-1000", "WITHIN-CIRCLE-10000", "WITHIN-CIRCLE-100000":
@ -544,9 +593,7 @@ func main() {
) )
} }
case "EVAL": case "EVAL":
if redis { if !redis {
break
}
var i int64 var i int64
getScript := "return tile38.call('GET', KEYS[1], ARGV[1], 'point')" getScript := "return tile38.call('GET', KEYS[1], ARGV[1], 'point')"
get4Script := get4Script :=
@ -563,6 +610,7 @@ func main() {
fmt.Println("GET FOUR SCRIPT: " + get4Script) fmt.Println("GET FOUR SCRIPT: " + get4Script)
fmt.Println("SET SCRIPT: " + setScript) fmt.Println("SET SCRIPT: " + setScript)
} }
redbench.Bench("EVAL (set point)", addr, opts, prepFn, redbench.Bench("EVAL (set point)", addr, opts, prepFn,
func(buf []byte) []byte { func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1) i := atomic.AddInt64(&i, 1)
@ -590,22 +638,19 @@ func main() {
redbench.Bench("EVALRO (get point)", addr, opts, prepFn, redbench.Bench("EVALRO (get point)", addr, opts, prepFn,
func(buf []byte) []byte { func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1) i := atomic.AddInt64(&i, 1)
args := []string{"EVALRO", getScript, "1", "key:bench", "id:" + strconv.FormatInt(i, 10)} return redbench.AppendCommand(buf, "EVALRO", getScript, "1", "key:bench", "id:"+strconv.FormatInt(i, 10))
return redbench.AppendCommand(buf, args...)
}, },
) )
redbench.Bench("EVALRO (get 4 points)", addr, opts, prepFn, redbench.Bench("EVALRO (get 4 points)", addr, opts, prepFn,
func(buf []byte) []byte { func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1) i := atomic.AddInt64(&i, 1)
args := []string{ return redbench.AppendCommand(buf, "EVALRO", get4Script, "1",
"EVALRO", get4Script, "1",
"key:bench", "key:bench",
"id:" + strconv.FormatInt(i, 10), "id:"+strconv.FormatInt(i, 10),
"id:" + strconv.FormatInt(i+1, 10), "id:"+strconv.FormatInt(i+1, 10),
"id:" + strconv.FormatInt(i+2, 10), "id:"+strconv.FormatInt(i+2, 10),
"id:" + strconv.FormatInt(i+3, 10), "id:"+strconv.FormatInt(i+3, 10),
} )
return redbench.AppendCommand(buf, args...)
}, },
) )
redbench.Bench("EVALNA (get point)", addr, opts, prepFn, redbench.Bench("EVALNA (get point)", addr, opts, prepFn,
@ -616,6 +661,7 @@ func main() {
) )
} }
} }
}
} }
const earthRadius = 6371e3 const earthRadius = 6371e3