forked from MichelDiz/dgraph-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.go
98 lines (81 loc) · 1.94 KB
/
queries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package tasks
import (
"context"
"fmt"
"math/rand"
"strconv"
"time"
"github.com/dgraph-io/dgo"
)
const (
qlGetFriendsOneHop = `query friends($a: string) {
friends(func: uid($a)) {
name
type
created_at
friend_of {
name
}
~friend_of {
name
}
xid
}
}`
qlGetFriendsTwoHop = `query friends($a: string) {
friends(func: uid($a)) {
name
type
created_at
friend_of {
name
friend_of {
name
}
}
~friend_of {
name
~friend_of {
name
}
}
xid
}
}`
)
func init() {
BenchTasks["get-friends-one-hop"] = GetFriendsOneHop
BenchTasks["get-friends-two-hop"] = GetFriendsTwoHop
}
func GetFriendsOneHop(dgraphCli *dgo.Dgraph) error {
start := time.Now()
uid := rand.Int63n(MaxUid)
txn := dgraphCli.NewReadOnlyTxn()
resp, err := txn.QueryWithVars(context.Background(), qlGetFriendsOneHop, map[string]string{"$a": strconv.FormatInt(uid, 10)})
if err != nil {
counters.WithLabelValues("get-friends-one-hop", "ERROR").Inc()
fmt.Printf("Failed to query friends for uid %d: %v\n", uid, err)
return err
}
// fmt.Println(string(resp.Json))
_ = resp.Json
counters.WithLabelValues("get-friends-one-hop", "OK").Inc()
durations.WithLabelValues("get-friends-one-hop", "OK").Observe(time.Since(start).Seconds())
return nil
}
func GetFriendsTwoHop(dgraphCli *dgo.Dgraph) error {
start := time.Now()
uid := rand.Int63n(MaxUid)
txn := dgraphCli.NewReadOnlyTxn()
resp, err := txn.QueryWithVars(context.Background(), qlGetFriendsTwoHop, map[string]string{"$a": strconv.FormatInt(uid, 10)})
if err != nil {
counters.WithLabelValues("get-friends-two-hop", "ERROR").Inc()
fmt.Printf("Failed to query friends for uid %d: %v\n", uid, err)
return err
}
// fmt.Println(string(resp.Json))
_ = resp.Json
counters.WithLabelValues("get-friends-two-hop", "OK").Inc()
durations.WithLabelValues("get-friends-two-hop", "OK").Observe(time.Since(start).Seconds())
return nil
}