-
Notifications
You must be signed in to change notification settings - Fork 0
Use bytetstring instead of string for performance and switch proto libraries. #7
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
Changes from all commits
3b30c14
5c59a8c
cfd4db1
2850df4
91a4c93
a044a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ package serialization | |
import ( | ||
"context" | ||
"fmt" | ||
"github.com/go-kit/log/level" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/go-kit/log/level" | ||
|
||
snappy "github.com/eapache/go-xerial-snappy" | ||
"github.com/go-kit/log" | ||
"github.com/grafana/walqueue/types" | ||
|
@@ -161,7 +162,9 @@ func (s *serializer) flushToDisk(ctx actor.Context) error { | |
}() | ||
|
||
// This maps strings to index position in a slice. This is doing to reduce the file size of the data. | ||
strMapToIndex := make(map[string]uint32) | ||
// Assume roughly each series has 10 labels, we do this because at very large mappings growing the map took up to 5% of cpu time. | ||
// By pre allocating it that disappeared. | ||
strMapToIndex := make(map[string]uint32, len(s.series)*10) | ||
Comment on lines
+165
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Kinda surprised it had so big impact. Maybe we can track the average size of this and autotune it at runtime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also surprised. This trades memory for cpu, ie this map is bigger than we actually need in most cases since we store only the unique strings. |
||
for i, ts := range s.series { | ||
ts.FillLabelMapping(strMapToIndex) | ||
group.Series[i] = ts | ||
|
@@ -171,9 +174,9 @@ func (s *serializer) flushToDisk(ctx actor.Context) error { | |
group.Metadata[i] = ts | ||
} | ||
|
||
stringsSlice := make([]string, len(strMapToIndex)) | ||
stringsSlice := make([]types.ByteString, len(strMapToIndex)) | ||
for stringValue, index := range strMapToIndex { | ||
stringsSlice[index] = stringValue | ||
stringsSlice[index] = types.ByteString(stringValue) | ||
} | ||
group.Strings = stringsSlice | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this to inside the func had no impact on CPU but saved memory.