Skip to content

Commit

Permalink
perf(sroar): Use latest sroar and add histogram in the sbs tool (#7982)
Browse files Browse the repository at this point in the history
This commit brings in sroar with some more optimizations like
cleanup of the bitmap, it also implements histogram in the sbs
tool, which will help in better comparison.
ahsanbarkati authored Aug 12, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 18fd841 commit 3233a70
Showing 6 changed files with 90 additions and 27 deletions.
3 changes: 2 additions & 1 deletion contrib/sbs/go.mod
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@ go 1.16

require (
github.com/dgraph-io/dgo/v210 v210.0.0-20210421093152-78a2fece3ebd
github.com/pkg/errors v0.8.1
github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
google.golang.org/grpc v1.38.0
6 changes: 4 additions & 2 deletions contrib/sbs/go.sum
Original file line number Diff line number Diff line change
@@ -143,8 +143,9 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 h1:twflg0XRTjwKpxb/jFExr4HGq6on2dEOmnL6FV+fgPw=
github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
@@ -204,8 +205,9 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
32 changes: 11 additions & 21 deletions contrib/sbs/sbs.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import (
"fmt"
"io/ioutil"
"os"
"reflect"
"regexp"
"strconv"
"sync"
@@ -153,6 +152,8 @@ func processLog(dcLeft, dcRight *dgo.Dgraph) {
defer f.Close()

var failed, total uint64
hist := newHistogram([]float64{0, 0.5, 1, 1.5, 2})

reqCh := make(chan *api.Request, opts.numGo*5)

var wg sync.WaitGroup
@@ -172,6 +173,14 @@ func processLog(dcLeft, dcRight *dgo.Dgraph) {
klog.Infof("Failed Query: %s \nVars: %v\nLeft: %v\nRight: %v\n",
r.Query, r.Vars, respL, respR)
}

lt := float64(respL.Latency.ProcessingNs) / 1e6
rt := float64(respR.Latency.ProcessingNs) / 1e6
// Only consider the processing time > 10 ms for histogram to avoid noise in ratios.
if lt > 10 || rt > 10 {
ratio := rt / lt
hist.add(ratio)
}
atomic.AddUint64(&total, 1)
}
}
@@ -199,6 +208,7 @@ func processLog(dcLeft, dcRight *dgo.Dgraph) {
for range ticker.C {
klog.Infof("Total: %d Failed: %d\n", atomic.LoadUint64(&total),
atomic.LoadUint64(&failed))
hist.show()
}
}()
wg.Wait()
@@ -316,23 +326,3 @@ func runQuery(r *api.Request, client *dgo.Dgraph) (*api.Response, error) {
}
return resp, nil
}

func areEqualJSON(s1, s2 string) bool {
var o1, o2 interface{}

err := json.Unmarshal([]byte(s1), &o1)
if err != nil {
return false
}
err = json.Unmarshal([]byte(s2), &o2)
if err != nil {
return false
}
return reflect.DeepEqual(o1, o2)
}

func check(err error) {
if err != nil {
panic(err)
}
}
70 changes: 70 additions & 0 deletions contrib/sbs/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"encoding/json"
"fmt"
"reflect"
"sync/atomic"
)

type histogram struct {
bins []float64
count []uint64
total uint64
}

func newHistogram(bins []float64) *histogram {
return &histogram{
bins: bins,
count: make([]uint64, len(bins)),
}
}

func (h *histogram) add(v float64) {
idx := 0
for i := 0; i < len(h.bins); i++ {
if i+1 >= len(h.bins) {
idx = i
break
}
if h.bins[i] <= v && h.bins[i+1] > v {
idx = i
break
}
}
atomic.AddUint64(&h.count[idx], 1)
atomic.AddUint64(&h.total, 1)
}

func (h *histogram) show() {
fmt.Printf("-------------- Histogram --------------\nTotal samples: %d\n",
atomic.LoadUint64(&h.total))
for i := 0; i < len(h.bins); i++ {
pert := float64(atomic.LoadUint64(&h.count[i])) / float64(atomic.LoadUint64(&h.total))
if i+1 >= len(h.bins) {
fmt.Printf("%.2f - infi --> %.2f\n", h.bins[i], pert)
continue
}
fmt.Printf("%.2f - %.2f --> %.2f\n", h.bins[i], h.bins[i+1], pert)
}
}

func areEqualJSON(s1, s2 string) bool {
var o1, o2 interface{}

err := json.Unmarshal([]byte(s1), &o1)
if err != nil {
return false
}
err = json.Unmarshal([]byte(s2), &o2)
if err != nil {
return false
}
return reflect.DeepEqual(o1, o2)
}

func check(err error) {
if err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ require (
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15
github.com/dgraph-io/ristretto v0.1.0
github.com/dgraph-io/simdjson-go v0.3.0
github.com/dgraph-io/sroar v0.0.0-20210810060359-2dcd866b0b1f
github.com/dgraph-io/sroar v0.0.0-20210812083743-986f6c1098e2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -182,8 +182,8 @@ github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/Lu
github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug=
github.com/dgraph-io/simdjson-go v0.3.0 h1:h71LO7vR4LHMPUhuoGN8bqGm1VNfGOlAG8BI6iDUKw0=
github.com/dgraph-io/simdjson-go v0.3.0/go.mod h1:Otpysdjaxj9OGaJusn4pgQV7OFh2bELuHANq0I78uvY=
github.com/dgraph-io/sroar v0.0.0-20210810060359-2dcd866b0b1f h1:t0+mRMDoMgWykf89mPKW9RaeFb3ujM7HoISogMXsaDo=
github.com/dgraph-io/sroar v0.0.0-20210810060359-2dcd866b0b1f/go.mod h1:bdNPtQmcxoIQVkZEWZvX0n0/IDlHFab397xdBlP4OoE=
github.com/dgraph-io/sroar v0.0.0-20210812083743-986f6c1098e2 h1:r6+OcMwALExXQjyoZPBBKjGHTTioBU39J1aagrxgzN4=
github.com/dgraph-io/sroar v0.0.0-20210812083743-986f6c1098e2/go.mod h1:bdNPtQmcxoIQVkZEWZvX0n0/IDlHFab397xdBlP4OoE=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=

0 comments on commit 3233a70

Please sign in to comment.