diff --git a/pkg/phlaredb/symdb/block_writer.go b/pkg/phlaredb/symdb/block_writer.go index b23121bbb7..f110a88cfc 100644 --- a/pkg/phlaredb/symdb/block_writer.go +++ b/pkg/phlaredb/symdb/block_writer.go @@ -136,13 +136,17 @@ func (w *writer) Flush() (err error) { func (w *writer) writeStacktraces(partition *PartitionWriter) (err error) { for ci, c := range partition.stacktraces.chunks { + stacks := c.stacks + if stacks == 0 { + stacks = uint32(len(partition.stacktraces.hashToIdx)) + } h := StacktraceChunkHeader{ Offset: w.stacktraces.w.offset, Size: 0, // Set later. Partition: partition.header.Partition, ChunkIndex: uint16(ci), ChunkEncoding: ChunkEncodingGroupVarint, - Stacktraces: c.stacks, + Stacktraces: stacks, StacktraceNodes: c.tree.len(), StacktraceMaxDepth: 0, // TODO StacktraceMaxNodes: c.partition.maxNodesPerChunk, diff --git a/pkg/phlaredb/symdb/symdb.go b/pkg/phlaredb/symdb/symdb.go index f3e73c13d5..f5b7b29d61 100644 --- a/pkg/phlaredb/symdb/symdb.go +++ b/pkg/phlaredb/symdb/symdb.go @@ -110,10 +110,10 @@ func DefaultConfig() *Config { return &Config{ Dir: DefaultDirName, Stacktraces: StacktracesConfig{ - // A million of nodes ensures predictable - // memory consumption, although causes a - // small overhead. - MaxNodesPerChunk: 1 << 20, + // At the moment chunks are loaded in memory at once. + // Due to the fact that chunking causes some duplication, + // it's better to keep them large. + MaxNodesPerChunk: 4 << 20, }, Parquet: ParquetConfig{ MaxBufferRowCount: 100 << 10, diff --git a/pkg/phlaredb/symdb/symdb_test.go b/pkg/phlaredb/symdb/symdb_test.go index 94f95b0fd0..69a9561b7d 100644 --- a/pkg/phlaredb/symdb/symdb_test.go +++ b/pkg/phlaredb/symdb/symdb_test.go @@ -141,3 +141,39 @@ func treeFingerprint(t *phlaremodel.Tree) [][2]uint64 { sort.Slice(m, func(i, j int) bool { return m[i][0] < m[j][0] }) return m } + +func Test_Stats(t *testing.T) { + s := memSuite{ + t: t, + files: [][]string{{"testdata/profile.pb.gz"}}, + config: &Config{ + Dir: t.TempDir(), + Stacktraces: StacktracesConfig{ + MaxNodesPerChunk: 4 << 20, + }, + Parquet: ParquetConfig{ + MaxBufferRowCount: 100 << 10, + }, + }, + } + + s.init() + bs := blockSuite{memSuite: &s} + bs.flush() + defer bs.teardown() + + p, err := bs.reader.Partition(context.Background(), 0) + require.NoError(t, err) + + var actual PartitionStats + p.WriteStats(&actual) + expected := PartitionStats{ + StacktracesTotal: 611, + MaxStacktraceID: 1793, + LocationsTotal: 762, + MappingsTotal: 3, + FunctionsTotal: 507, + StringsTotal: 700, + } + require.Equal(t, expected, actual) +}