Skip to content

Commit aa1a4b3

Browse files
committed
perf(v2): static parquet page buffer size
1 parent 0e4976a commit aa1a4b3

File tree

4 files changed

+9
-48
lines changed

4 files changed

+9
-48
lines changed

pkg/experiment/block/block.go

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,10 @@ const (
2323
symbolsPrefetchSize = 32 << 10
2424
)
2525

26-
func estimateReadBufferSize(s int64) int {
27-
const minSize = 64 << 10
28-
const maxSize = 1 << 20
29-
// Parquet has global buffer map, where buffer size is key,
30-
// so we want a low cardinality here.
31-
e := nextPowerOfTwo(uint32(s / 10))
32-
if e < minSize {
33-
return minSize
34-
}
35-
return int(min(e, maxSize))
36-
}
37-
38-
// This is a verbatim copy of estimateReadBufferSize.
39-
// It's kept for the sake of clarity and to avoid confusion.
40-
func estimatePageBufferSize(s int64) int {
41-
const minSize = 64 << 10
42-
const maxSize = 1 << 20
43-
e := nextPowerOfTwo(uint32(s / 10))
44-
if e < minSize {
45-
return minSize
46-
}
47-
return int(min(e, maxSize))
48-
}
26+
const (
27+
parquetReadBufferSize = 2 << 20
28+
parquetPageWriteBufferSize = 4 << 20
29+
)
4930

5031
func estimateFooterSize(size int64) int64 {
5132
var s int64
@@ -67,17 +48,3 @@ func estimateFooterSize(size int64) int64 {
6748
}
6849
return s
6950
}
70-
71-
func nextPowerOfTwo(n uint32) uint32 {
72-
if n == 0 {
73-
return 1
74-
}
75-
n--
76-
n |= n >> 1
77-
n |= n >> 2
78-
n |= n >> 4
79-
n |= n >> 8
80-
n |= n >> 16
81-
n++
82-
return n
83-
}

pkg/experiment/block/compaction.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,7 @@ func (m *datasetCompaction) registerSampleObserver(observer SampleObserver) {
374374
}
375375

376376
func (m *datasetCompaction) open(ctx context.Context, w io.Writer) (err error) {
377-
var estimatedProfileTableSize int64
378-
for _, ds := range m.datasets {
379-
estimatedProfileTableSize += ds.sectionSize(SectionProfiles)
380-
}
381-
pageBufferSize := estimatePageBufferSize(estimatedProfileTableSize)
382-
m.profilesWriter = newProfileWriter(pageBufferSize, w)
383-
377+
m.profilesWriter = newProfileWriter(w)
384378
m.indexRewriter = newIndexRewriter()
385379
m.symbolsRewriter = newSymbolsRewriter()
386380

pkg/experiment/block/section_profiles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func openProfileTable(_ context.Context, s *Dataset) (err error) {
4343
parquet.SkipBloomFilters(true),
4444
parquet.SkipPageIndex(true),
4545
parquet.FileReadMode(parquet.ReadModeAsync),
46-
parquet.ReadBufferSize(estimateReadBufferSize(size)))
46+
parquet.ReadBufferSize(parquetReadBufferSize))
4747
}
4848
if err != nil {
4949
return fmt.Errorf("opening profile parquet table: %w", err)
@@ -163,12 +163,12 @@ type profilesWriter struct {
163163
profiles uint64
164164
}
165165

166-
func newProfileWriter(pageBufferSize int, w io.Writer) *profilesWriter {
166+
func newProfileWriter(w io.Writer) *profilesWriter {
167167
return &profilesWriter{
168168
buf: make([]parquet.Row, 1),
169169
GenericWriter: parquet.NewGenericWriter[*schemav1.Profile](w,
170170
parquet.CreatedBy("github.com/grafana/pyroscope/", build.Version, build.Revision),
171-
parquet.PageBufferSize(pageBufferSize),
171+
parquet.PageBufferSize(parquetPageWriteBufferSize),
172172
// Note that parquet keeps ALL RG pages in memory (ColumnPageBuffers).
173173
parquet.MaxRowsPerRowGroup(maxRowsPerRowGroup),
174174
schemav1.ProfilesSchema,

pkg/experiment/ingester/memdb/profiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/grafana/pyroscope/pkg/util/build"
1111
)
1212

13-
const segmentsParquetWriteBufferSize = 32 << 10
13+
const segmentsParquetWriteBufferSize = 256 << 10
1414

1515
func WriteProfiles(metrics *HeadMetrics, profiles []v1.InMemoryProfile) ([]byte, error) {
1616
buf := &bytes.Buffer{}

0 commit comments

Comments
 (0)