What I want to do
I want to have the best performance query to get a recommended list.
What I did
-
I have a list of users, each user has a unique address and a list of tags (tag can be anything the user has: tokens, projects - number of tags of each user is from 5 → 500 tags).
-
I want to get a list of 10 users whose tags are most similar to the current user.
-
My current query get bigger latency when the number of user increase (>10M users)
-
Here is my dgraph data model:
{
"data": {
"user": [
{
"address": "0x79852a2b8386587daad501d90674996dd19d88c9",
"tagged": [
{
// token
"name": "token:bsc_btc"
},
{
// chain
"name": "chain:bsc"
},
{
// project
"name": "project:bsc_aavev3"
}
],
}
]
}
- And here is my current query:
{
my_token(func: eq(address, "0x80c1adfb1192d781a03cae1ac84faecac5c91a8a")) {
t as tagged
}
var(func: type(User)) {
x as count(tagged @filter(uid(t)))
norm as math(1)
score as math(x*norm)
}
suggestions(func: uid(score), orderdesc: val(score), first: 10) {
address
val(score)
}
}
The query performance get bigger latency when the number of user increase
- 200 record
"server_latency": {
"parsing_ns": 93100,
"processing_ns": 1513700,
"encoding_ns": 37700,
"assign_timestamp_ns": 834700,
"total_ns": 2.531.400
},
- 4000 record
"extensions": {
"server_latency": {
"parsing_ns": 94400,
"processing_ns": 6001900,
"encoding_ns": 30800,
"assign_timestamp_ns": 630300,
"total_ns": 6.824.800
},
- 20.000 record
"extensions": {
"server_latency": {
"parsing_ns": 1465400,
"processing_ns": 167639600,
"encoding_ns": 110500,
"assign_timestamp_ns": 775900,
"total_ns": 170.061.400
}
- This is my current docker-compose
version: "3.2"
networks:
dgraph:
services:
zero1:
image: dgraph/dgraph:v21.03.2
volumes:
- ./dgraph_data/zero1:/dgraph
ports:
- "5081:5080"
- "6081:6080"
networks:
- dgraph
command: dgraph zero --my=zero1:5080 --replicas 3 --raft="idx=1"
zero2:
image: dgraph/dgraph:v21.03.2
depends_on:
- zero1
volumes:
- ./dgraph_data/zero2:/dgraph
ports:
- "5082:5080"
- "6082:6080"
networks:
- dgraph
command: dgraph zero --my=zero2:5080 --replicas 3 --peer zero1:5080 --raft="idx=2"
zero3:
image: dgraph/dgraph:v21.03.2
depends_on:
- zero2
volumes:
- ./dgraph_data/zero3:/dgraph
ports:
- "5083:5080"
- "6083:6080"
networks:
- dgraph
command: dgraph zero --my=zero3:5080 --replicas 3 --peer zero1:5080 --raft="idx=3"
alpha1:
image: dgraph/dgraph:v21.03.2
depends_on:
- zero3
volumes:
- ./dgraph_data/alpha1:/dgraph
ports:
- "8081:8080"
- "9081:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha1:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
alpha2:
image: dgraph/dgraph:v21.03.2
depends_on:
- alpha1
volumes:
- ./dgraph_data/alpha2:/dgraph
ports:
- "8082:8080"
- "9082:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha2:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
alpha3:
image: dgraph/dgraph:v21.03.2
depends_on:
- alpha2
volumes:
- ./dgraph_data/alpha3:/dgraph
ports:
- "8083:8080"
- "9083:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha3:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
alpha4:
image: dgraph/dgraph:v21.03.2
depends_on:
- alpha3
volumes:
- ./dgraph_data/alpha4:/dgraph
ports:
- "8084:8080"
- "9084:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha4:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
alpha5:
image: dgraph/dgraph:v21.03.2
depends_on:
- alpha4
volumes:
- ./dgraph_data/alpha5:/dgraph
ports:
- "8085:8080"
- "9085:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha5:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
alpha6:
image: dgraph/dgraph:v21.03.2
depends_on:
- alpha5
volumes:
- ./dgraph_data/alpha6:/dgraph
ports:
- "8086:8080"
- "9086:9080"
networks:
- dgraph
command: dgraph alpha --my=alpha6:7080 --zero=zero1:5080,zero2:5080,zero3:5080
--security "whitelist=0.0.0.0/0"
--telemetry "reports=false; sentry=false;"
ratel:
image: dgraph/ratel:v21.03.2
ports:
- "8000:8000"
networks:
- dgraph
command: dgraph-ratel