-
Notifications
You must be signed in to change notification settings - Fork 1.5k
opt(rdf-output): Make RDF output generation concurrent #7988
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. The code is nice and simple. Yet, can be further simplified. Have some suggestions.
Reviewable status: 0 of 1 files reviewed, 5 unresolved discussions (waiting on @ahsanbarkati)
query/outputrdf.go, line 32 at r1 (raw file):
) const numGo = 32
I'd just give it 4 goroutines.
query/outputrdf.go, line 43 at r1 (raw file):
// ToRDF converts the given subgraph list into rdf format. func ToRDF(l *Latency, sgl []*SubGraph) ([]byte, error) { var fwg, wg sync.WaitGroup
what does fwg mean?
query/outputrdf.go, line 45 at r1 (raw file):
var fwg, wg sync.WaitGroup b := &rdfBuilder{ sgCh: make(chan *SubGraph, 1000),
16 should be enough.
query/outputrdf.go, line 46 at r1 (raw file):
b := &rdfBuilder{ sgCh: make(chan *SubGraph, 1000), outCh: make(chan *bytes.Buffer, 1000),
You could technically avoid this by just putting a mutex lock around the final buffer.
query/outputrdf.go, line 103 at r1 (raw file):
defer wg.Done() for buf := range b.outCh { b.buf = append(b.buf, buf.Bytes()...)
This finalize isn't required. You could just create a write func in rdfBuilder, which takes a mutex lock and does the write from within.
That would also simplify how this code reads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 files reviewed, 5 unresolved discussions (waiting on @ahsanbarkati and @manishrjain)
query/outputrdf.go, line 32 at r1 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
I'd just give it 4 goroutines.
Done.
query/outputrdf.go, line 45 at r1 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
16 should be enough.
Done.
query/outputrdf.go, line 46 at r1 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
You could technically avoid this by just putting a mutex lock around the final buffer.
Done.
query/outputrdf.go, line 103 at r1 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
This finalize isn't required. You could just create a write func in rdfBuilder, which takes a mutex lock and does the write from within.
That would also simplify how this code reads.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ahsanbarkati)
query/outputrdf.go, line 148 at r2 (raw file):
func (b *rdfBuilder) write(buf *bytes.Buffer) { b.Lock() defer b.Unlock()
you could just move unlock to after b.buf. Avoid using a defer. Micro-opt.
For RDF format output, the order of rdf's doesn't matter, so we can make them concurrent.
This change is