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(memory): Use z.Calloc for allocating KVList #1563

Merged
merged 25 commits into from
Oct 13, 2020
Merged

Conversation

manishrjain
Copy link
Contributor

@manishrjain manishrjain commented Oct 12, 2020

KVs can take up a lot of memory in the stream framework. With this change, we allocate them using z.Allocator and release them after the final KVList is sent out.

This change is Reviewable

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.

LGTM. 26 rules errored during the review.

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.

LGTM. 26 rules errored during the review.

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.

LGTM. 27 rules errored during the review.

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.

LGTM. 26 rules errored during the review.

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.

LGTM. 26 rules errored during the review.

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.

LGTM. 26 rules errored during the review.

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.

LGTM. 26 rules errored during the review.

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. 21 rules errored during the review.

stream.go Outdated
@@ -175,17 +203,21 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocatorId = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

Initialize outList 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.

1 issues found. 22 rules errored during the review.

stream.go Outdated
@@ -175,6 +202,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocatorId = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

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

View Rule

Add an --encryption-key-file flag to the badger stream tool to support encrypted databases.

Changes:

* Add --encryption-key-file flag
* Set block and index cache sizes to fix panic when running stream.
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.

3 issues found. 1 rules errored during the review.

@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocRef = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

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

View Rule

@@ -50,7 +52,10 @@ type collector struct {
}

func (c *collector) Send(list *bpb.KVList) error {
c.kv = append(c.kv, list.Kv...)
for _, kv := range list.Kv {
cp := proto.Clone(kv).(*bpb.KV)
Copy link

Choose a reason for hiding this comment

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

Unchecked type assertions can cause panics. Check for success with the x, ok := y.(type) style.

View Rule

@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocRef = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

Initialize outList 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.

3 issues found. 1 rules errored during the review.

@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocRef = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

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

View Rule

@@ -50,7 +52,10 @@ type collector struct {
}

func (c *collector) Send(list *bpb.KVList) error {
c.kv = append(c.kv, list.Kv...)
for _, kv := range list.Kv {
cp := proto.Clone(kv).(*bpb.KV)
Copy link

Choose a reason for hiding this comment

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

Unchecked type assertions can cause panics. Check for success with the x, ok := y.(type) style.

View Rule

@@ -175,6 +206,7 @@ func (st *Stream) produceKVs(ctx context.Context, threadId int) error {
streamId := atomic.AddUint32(&st.nextStreamId, 1)

outList := new(pb.KVList)
outList.AllocRef = st.newAllocator(threadId).Ref
Copy link

Choose a reason for hiding this comment

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

Initialize outList 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.

}
return nil
// Mark the stream as done.
outList.Kv = append(outList.Kv, &pb.KV{
Copy link

Choose a reason for hiding this comment

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

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

View Rule

}
return nil
// Mark the stream as done.
outList.Kv = append(outList.Kv, &pb.KV{
Copy link

Choose a reason for hiding this comment

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

Initialize outList 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.

LGTM. 1 rules errored during the review.

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.

LGTM. 3 rules errored during the review.

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.

LGTM. 7 rules errored during the review.

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.

LGTM. 16 rules errored during the review.

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.

LGTM. 11 rules errored during the review.

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.

LGTM. 21 rules errored during the review.

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.

LGTM. 21 rules errored during the review.

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.

LGTM. 1 rules errored during the review.

@manishrjain manishrjain merged commit 8d26d52 into master Oct 13, 2020
@manishrjain manishrjain deleted the mrjn/kvlist2 branch October 13, 2020 21:31
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.

LGTM. 4 rules errored during the review.

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.

LGTM. 12 rules errored during the review.

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