mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: imrpove cache effectiveness for time series ids matching the given filters
Previously the maximum cache lifetime has been limited by 10 seconds. Now it is extended up to a day. This should reduce CPU usage in the following cases: * when querying recently added data with small churn rate for time series * when querying historical data
This commit is contained in:
parent
40df42e1e5
commit
3ad7566a87
1 changed files with 18 additions and 13 deletions
|
@ -462,12 +462,13 @@ func marshalTagFiltersKey(dst []byte, tfss []*TagFilters, tr TimeRange, versione
|
|||
if versioned {
|
||||
prefix = atomic.LoadUint64(&tagFiltersKeyGen)
|
||||
}
|
||||
const cacheGranularityMs = 1000 * 10
|
||||
startTime := (uint64(tr.MinTimestamp) / cacheGranularityMs) * cacheGranularityMs
|
||||
endTime := (uint64(tr.MaxTimestamp) / cacheGranularityMs) * cacheGranularityMs
|
||||
// Round start and end times to per-day granularity according to per-day inverted index.
|
||||
startDate := uint64(tr.MinTimestamp) / msecPerDay
|
||||
endDate := uint64(tr.MaxTimestamp) / msecPerDay
|
||||
dst = append(dst, tagFiltersKeyVersion)
|
||||
dst = encoding.MarshalUint64(dst, prefix)
|
||||
dst = encoding.MarshalUint64(dst, startTime)
|
||||
dst = encoding.MarshalUint64(dst, endTime)
|
||||
dst = encoding.MarshalUint64(dst, startDate)
|
||||
dst = encoding.MarshalUint64(dst, endDate)
|
||||
if len(tfss) == 0 {
|
||||
return dst
|
||||
}
|
||||
|
@ -482,6 +483,18 @@ func marshalTagFiltersKey(dst []byte, tfss []*TagFilters, tr TimeRange, versione
|
|||
return dst
|
||||
}
|
||||
|
||||
// The version for tagCache key.
|
||||
// Update it every time key generation scheme changes at marshalTagFiltersKey.
|
||||
const tagFiltersKeyVersion = 1
|
||||
|
||||
func invalidateTagCache() {
|
||||
// This function must be fast, since it is called each
|
||||
// time new timeseries is added.
|
||||
atomic.AddUint64(&tagFiltersKeyGen, 1)
|
||||
}
|
||||
|
||||
var tagFiltersKeyGen uint64
|
||||
|
||||
func marshalTSIDs(dst []byte, tsids []TSID) []byte {
|
||||
dst = encoding.MarshalUint64(dst, uint64(len(tsids)))
|
||||
for i := range tsids {
|
||||
|
@ -514,14 +527,6 @@ func unmarshalTSIDs(dst []TSID, src []byte) ([]TSID, error) {
|
|||
return dst, nil
|
||||
}
|
||||
|
||||
func invalidateTagCache() {
|
||||
// This function must be fast, since it is called each
|
||||
// time new timeseries is added.
|
||||
atomic.AddUint64(&tagFiltersKeyGen, 1)
|
||||
}
|
||||
|
||||
var tagFiltersKeyGen uint64
|
||||
|
||||
// getTSIDByNameNoCreate fills the dst with TSID for the given metricName.
|
||||
//
|
||||
// It returns io.EOF if the given mn isn't found locally.
|
||||
|
|
Loading…
Reference in a new issue