I do some profile on dgraph. Basically it is getting the timeline of the social user. I found it use over 900% CPU time in my 16core machine. I have do some profile using pprof, and the problem is in the processSort function(worker/sort.go), sortWithIndex and sortWithoutIndex are doing together(of course the result will not return in 3ms). Could somebody explain why dgraph do in this way?
go func() {
select {
case <-time.After(3 * time.Millisecond):
// Wait between ctx chan and time chan.
case <-ctx.Done():
resCh <- &sortresult{err: ctx.Err()}
return
}
r := sortWithoutIndex(cctx, ts)
resCh <- r
}()
go func() {
sr := sortWithIndex(cctx, ts)
resCh <- sr
}()