Skip to content

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

Merged
merged 8 commits into from
Aug 16, 2021

Conversation

ahsanbarkati
Copy link
Contributor

@ahsanbarkati ahsanbarkati commented Aug 16, 2021

For RDF format output, the order of rdf's doesn't matter, so we can make them concurrent.


This change is Reviewable

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: 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.

Copy link
Contributor Author

@ahsanbarkati ahsanbarkati left a 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.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Feel free to merge.

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.

@ahsanbarkati ahsanbarkati merged commit 72bee93 into master Aug 16, 2021
@ahsanbarkati ahsanbarkati deleted the ahsan/concurrent-rdf branch August 16, 2021 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants