Skip to content
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

opt(builder): Use z.Allocator for building tables #1576

Merged
merged 28 commits into from
Nov 3, 2020

Conversation

ahsanbarkati
Copy link
Contributor

@ahsanbarkati ahsanbarkati commented Oct 28, 2020

Avoid Go memory spikes by using z.Allocator to allocate blocks during table generation. Also avoid having to copy data over, unless necessary -- instead write the data directly to the mmapped file.

With these changes, we're able to load 1 billion randomly generated 32-byte keys, 128-byte values in 1.5 hrs, with memory usage maxing out to 5 GB.


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.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @ahsanbarkati, @jarifibrahim, and @manishrjain)


table/builder.go, line 251 at r1 (raw file):

	defer b.bufLock.Unlock()
	b.buf.AllocateOffset(int(sz))
	b.sz += sz

If you're seeing some issues, then maybe do an assert in a few places about b.sz == LenNoPadding. But, ideally, we shouldn't be using b.sz at all?

Copy link

@codelingo codelingo bot left a comment

Choose a reason for hiding this comment

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

1 issues found. 1 rules errored during the review.

table/builder.go Outdated

func (bb *bblock) Append(data []byte) {
n := copy(bb.data[bb.end:], data)
bb.end += n
Copy link

Choose a reason for hiding this comment

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

Initialize n using a composite literal to simplify the code. as specified in Effective Go

View Rule

Copy link

@codelingo codelingo bot left a comment

Choose a reason for hiding this comment

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

2 issues found. 1 rules errored during the review.

table/builder.go Outdated Show resolved Hide resolved
table/builder.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

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

LGTM

table/builder_test.go Show resolved Hide resolved
Copy link

@codelingo codelingo bot left a comment

Choose a reason for hiding this comment

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

1 issues found. 1 rules errored during the review.

levels.go Outdated
// Expected.
} else if err != nil {
return nil, y.Wrapf(err, "while creating table: %s", fname)
} else {
Copy link

Choose a reason for hiding this comment

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

Omit unnecessary else when if doesn't flow into the next statement. as specified in Effective Go

View Rule

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.

Reviewed 5 of 13 files at r8, 1 of 2 files at r9, 4 of 7 files at r10, 9 of 9 files at r11.
Dismissed @codelingo[bot] from 3 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ahsanbarkati)


stream_writer.go, line 412 at r11 (raw file):

		data := builder.Finish()
		var err error
		if tbl, err = table.OpenInMemoryTable(data, fileID, builder.Opts()); err != nil {

might consider passing the builder over to OpenInMemoryTable.

@manishrjain manishrjain changed the title fix(builder): Use z.buffer for the builder opt(builder): Use z.Allocator for building tables Nov 3, 2020
@manishrjain manishrjain merged commit e2e08f9 into master Nov 3, 2020
@manishrjain manishrjain deleted the ahsan/mmap-builder branch November 3, 2020 22:12
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.

3 participants