-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dgraph very bad memory usage when serialize query result #982
Comments
@Rader Can you please share the mutations so that we can reproduce the issue and fix it. Thanks for reporting this. We will investigate |
@janardhan1993 I did what exactly the data loader did. First I generate RDFs, then call func (r *DevRepo) genClickMutation(pairs []DevMsgPair) string {
var buf bytes.Buffer
for _, pair := range pairs {
clickID := uuid.NewV4().String()
// properties
buf.WriteString(fmt.Sprintf("<dev_%s> <name> \"%s\" .\n", pair.DevID, pair.DevID))
buf.WriteString(fmt.Sprintf("<dev_%s> <tag> \"device\" .\n", pair.DevID))
buf.WriteString(fmt.Sprintf("<%s> <tag> \"click\" .\n", clickID))
buf.WriteString(fmt.Sprintf("<msg_%d> <name> \"%d\" .\n", pair.MsgID, pair.MsgID))
buf.WriteString(fmt.Sprintf("<msg_%d> <tag> \"msg\" .\n", pair.MsgID))
// predicates
buf.WriteString(fmt.Sprintf("<dev_%s> <device_click> <%s> .\n", pair.DevID, clickID))
buf.WriteString(fmt.Sprintf("<%s> <click_msg> <msg_%d> .\n", clickID, pair.MsgID))
}
return buf.String()
} |
Thanks for this issue, @Rader. This is a really interesting issue. We'll optimize our JSON conversion. Btw, note that directly encoding That's the conversion that's going on here. And I think what's happening is that there are too many nodes involved, each node requiring its own memory allocation on heap, which becomes a problem. |
Checkout https://github.com/json-iterator/go/, it's the fastest JSON encoder/decoder golang library I have seen so far. |
The encoder that we have avoids creating a map in the first place, which would be expensive. We directly create the JSON string representation. |
This is related to #1138. |
see the query first
It will get about 200w paths like this: msg(msg_1479709973679) -> device -> msg -> device.
If I run the query, Dgraph (v0.7.6) will use over 10G memory on my MAC pro with 16G, but still can not return the result as Dgraph will use all the CPU for GC. I mean this,
Go pprof will tell you the what's CPU is used for.
Most of the memory is used while doing serialization, converting to JSON for example as I sent request through HTTP. Total memory used is 4.52GB when I make this heap profile request. After that, the memory continue increasing to 10G.
If I stop building the fastJsonNode tree, and use the SubGraph object directly (see the line before return -
json.NewEncoder(bufw).Encode(sg)
) memory usage will be only a little more than 1G. And the CPU usage is about 100%, instead of 700% on my MAC. By the way, the JSON result sent to http client is about 60M bytes.The text was updated successfully, but these errors were encountered: