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

pkg/profilestore: Reduce allocs in writeSeries #2176

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/profilestore/profilecolumnstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ func (s *ProfileColumnStore) writeSeries(ctx context.Context, req *profilestorep
s.bufferPool,
)

ls := make(labels.Labels, 0)
for _, series := range req.Series {
ls := make(labels.Labels, 0, len(series.Labels.Labels))
ls = ls[:0]
for _, l := range series.Labels.Labels {
if valid := model.LabelName(l.Name).IsValid(); !valid {
return status.Errorf(codes.InvalidArgument, "invalid label name: %v", l.Name)
Expand Down
75 changes: 75 additions & 0 deletions pkg/profilestore/profilestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,78 @@ func Test_LabelName_Error(t *testing.T) {
})
}
}

func BenchmarkProfileColumnStoreWriteSeries(b *testing.B) {
ctx := context.Background()
logger := log.NewNopLogger()
reg := prometheus.NewRegistry()
tracer := trace.NewNoopTracerProvider().Tracer("")
col, err := frostdb.New()
require.NoError(b, err)
colDB, err := col.DB(ctx, "parca")
require.NoError(b, err)

schema, err := parcacol.Schema()
require.NoError(b, err)

table, err := colDB.Table(
"stacktraces",
frostdb.NewTableConfig(schema),
)
require.NoError(b, err)
m := metastoretest.NewTestMetastore(
b,
logger,
reg,
tracer,
)

api := NewProfileColumnStore(
logger,
tracer,
metastore.NewInProcessClient(m),
table,
schema,
)

req := &profilestorepb.WriteRawRequest{
Series: []*profilestorepb.RawProfileSeries{
{
Labels: &profilestorepb.LabelSet{
Labels: []*profilestorepb.Label{
{
Name: "n0",
Value: "v0",
},
},
},
},
{
Labels: &profilestorepb.LabelSet{
Labels: []*profilestorepb.Label{
{
Name: "n1",
Value: "v1",
},
},
},
},
{
Labels: &profilestorepb.LabelSet{
Labels: []*profilestorepb.Label{
{
Name: "n2",
Value: "v2",
},
},
},
},
},
}

b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
api.writeSeries(ctx, req)
}
}