-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compactor: avoid memory blow-up with stringlabels
When compiled with `-tags stringlabels`, the names and values point into a larger block of memory containing all labels. Garbage-collection considers the entire block "live" if you point to a part of it, so the map ends up retaining all labels for (nearly) all series. Cloning the string value avoids this problem, and we check first if the value is already in the map. Since the clone is more expensive, only do it when built with `-tags stringlabels`. Signed-off-by: Bryan Boreham <[email protected]>
- Loading branch information
Showing
3 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !stringlabels | ||
|
||
// Split out function which needs to be coded differently for stringlabels case. | ||
|
||
package tsdb | ||
|
||
func (sw *symbolsBatcher) addSymbol(sym string) error { | ||
sw.buffer[sym] = struct{}{} | ||
return sw.flushSymbols(false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build stringlabels | ||
|
||
// Split out function which needs to be coded differently for stringlabels case. | ||
|
||
package tsdb | ||
|
||
import "strings" | ||
|
||
func (sw *symbolsBatcher) addSymbol(sym string) error { | ||
if _, found := sw.buffer[sym]; !found { | ||
sym = strings.Clone(sym) // So we don't retain reference to the entire labels block. | ||
sw.buffer[sym] = struct{}{} | ||
} | ||
return sw.flushSymbols(false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters