@@ -134,6 +134,8 @@ type Config struct {
134
134
135
135
// For admin contact details
136
136
AdminLimitMessage string `yaml:"admin_limit_message"`
137
+
138
+ LabelsStringInterningEnabled bool `yaml:"labels_string_interning_enabled"`
137
139
}
138
140
139
141
// RegisterFlags adds the flags required to config this to the given FlagSet
@@ -158,13 +160,18 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
158
160
159
161
f .StringVar (& cfg .AdminLimitMessage , "ingester.admin-limit-message" , "please contact administrator to raise it" , "Customize the message contained in limit errors" )
160
162
163
+ f .BoolVar (& cfg .LabelsStringInterningEnabled , "ingester.labels-string-interning-enabled" , false , "Experimental: Enable string interning for metrics labels." )
161
164
}
162
165
163
166
func (cfg * Config ) Validate () error {
164
167
if err := cfg .LifecyclerConfig .Validate (); err != nil {
165
168
return err
166
169
}
167
170
171
+ if cfg .LabelsStringInterningEnabled {
172
+ logutil .WarnExperimentalUse ("String interning for metrics labels Enabled" )
173
+ }
174
+
168
175
return nil
169
176
}
170
177
@@ -296,6 +303,10 @@ type userTSDB struct {
296
303
// Cached shipped blocks.
297
304
shippedBlocksMtx sync.Mutex
298
305
shippedBlocks map [ulid.ULID ]struct {}
306
+
307
+ // Used to dedup strings and keep a single reference in memory
308
+ labelsStringInterningEnabled bool
309
+ interner util.Interner
299
310
}
300
311
301
312
// Explicitly wrapping the tsdb.DB functions that we use.
@@ -425,6 +436,9 @@ func (u *userTSDB) PostCreation(metric labels.Labels) {
425
436
}
426
437
u .seriesInMetric .increaseSeriesForMetric (metricName )
427
438
u .labelSetCounter .increaseSeriesLabelSet (u , metric )
439
+ if u .labelsStringInterningEnabled {
440
+ metric .InternStrings (u .interner .Intern )
441
+ }
428
442
}
429
443
430
444
// PostDeletion implements SeriesLifecycleCallback interface.
@@ -439,6 +453,9 @@ func (u *userTSDB) PostDeletion(metrics map[chunks.HeadSeriesRef]labels.Labels)
439
453
}
440
454
u .seriesInMetric .decreaseSeriesForMetric (metricName )
441
455
u .labelSetCounter .decreaseSeriesLabelSet (u , metric )
456
+ if u .labelsStringInterningEnabled {
457
+ metric .ReleaseStrings (u .interner .Release )
458
+ }
442
459
}
443
460
}
444
461
@@ -2047,8 +2064,10 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
2047
2064
ingestedAPISamples : util_math .NewEWMARate (0.2 , i .cfg .RateUpdatePeriod ),
2048
2065
ingestedRuleSamples : util_math .NewEWMARate (0.2 , i .cfg .RateUpdatePeriod ),
2049
2066
2050
- instanceLimitsFn : i .getInstanceLimits ,
2051
- instanceSeriesCount : & i .TSDBState .seriesCount ,
2067
+ instanceLimitsFn : i .getInstanceLimits ,
2068
+ instanceSeriesCount : & i .TSDBState .seriesCount ,
2069
+ interner : util .NewInterner (),
2070
+ labelsStringInterningEnabled : i .cfg .LabelsStringInterningEnabled ,
2052
2071
}
2053
2072
2054
2073
enableExemplars := false
0 commit comments