further memory optimizations
Some checks failed
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled

Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Callum Styan 2024-09-14 14:14:53 -07:00
parent 2c96cb629c
commit e94568f98a

View file

@ -1553,8 +1553,8 @@ func (s *shards) runShard(ctx context.Context, shardID int, queue *queue) {
} }
pendingDataV2 := make([]*writev2.TimeSeries, maxCount) pendingDataV2 := make([]*writev2.TimeSeries, maxCount)
for i := range pendingDataV2 { for i := range pendingDataV2 {
pendingDataV2[i] = writev2.TimeSeriesFromVTPool() pendingDataV2[i] = &writev2.TimeSeries{}
pendingDataV2[i].Samples = []*writev2.Sample{writev2.SampleFromVTPool()} pendingDataV2[i].Samples = []*writev2.Sample{&writev2.Sample{Value: 1, Timestamp: 0}}
} }
timer := time.NewTimer(time.Duration(s.qm.cfg.BatchSendDeadline)) timer := time.NewTimer(time.Duration(s.qm.cfg.BatchSendDeadline))
@ -1952,10 +1952,6 @@ func (s *shards) sendV2SamplesWithBackoff(ctx context.Context, samples []*writev
func populateV2TimeSeries(symbolTable *writev2.SymbolsTable, batch []timeSeries, pendingData []*writev2.TimeSeries, sendExemplars, sendNativeHistograms bool) (int, int, int, int) { func populateV2TimeSeries(symbolTable *writev2.SymbolsTable, batch []timeSeries, pendingData []*writev2.TimeSeries, sendExemplars, sendNativeHistograms bool) (int, int, int, int) {
var nPendingSamples, nPendingExemplars, nPendingHistograms, nPendingMetadata int var nPendingSamples, nPendingExemplars, nPendingHistograms, nPendingMetadata int
for nPending, d := range batch { for nPending, d := range batch {
for _, sample := range pendingData[nPending].Samples {
sample.ReturnToVTPool()
}
pendingData[nPending].Samples = pendingData[nPending].Samples[:0]
// todo: should we also safeguard against empty metadata here? // todo: should we also safeguard against empty metadata here?
if d.metadata != nil { if d.metadata != nil {
pendingData[nPending].Metadata = &writev2.Metadata{} pendingData[nPending].Metadata = &writev2.Metadata{}
@ -1984,10 +1980,10 @@ func populateV2TimeSeries(symbolTable *writev2.SymbolsTable, batch []timeSeries,
pendingData[nPending].LabelsRefs = symbolTable.SymbolizeLabels(d.seriesLabels, pendingData[nPending].LabelsRefs) pendingData[nPending].LabelsRefs = symbolTable.SymbolizeLabels(d.seriesLabels, pendingData[nPending].LabelsRefs)
switch d.sType { switch d.sType {
case tSample: case tSample:
sample := writev2.SampleFromVTPool() // we don't do any optimization to send multiple samples for the same timeseries
sample.Value = d.value // in a single proto time series, so this is safe at the moment
sample.Timestamp = d.timestamp pendingData[nPending].Samples[0].Value = d.value
pendingData[nPending].Samples = append(pendingData[nPending].Samples, sample) pendingData[nPending].Samples[0].Timestamp = d.timestamp
nPendingSamples++ nPendingSamples++
case tExemplar: case tExemplar:
exemplar := writev2.ExemplarFromVTPool() exemplar := writev2.ExemplarFromVTPool()
@ -2223,7 +2219,11 @@ func buildV2WriteRequest(logger log.Logger, samples []*writev2.TimeSeries, label
pBuf = &[]byte{} // For convenience in tests. Not efficient. pBuf = &[]byte{} // For convenience in tests. Not efficient.
} }
data, err := proto.Marshal(req) //data, err := proto.Marshal(req)
if len(*pBuf) < req.SizeVT() {
*pBuf = make([]byte, req.SizeVT())
}
size, err := req.MarshalToVT(*pBuf)
if err != nil { if err != nil {
return nil, highest, lowest, err return nil, highest, lowest, err
} }
@ -2233,7 +2233,7 @@ func buildV2WriteRequest(logger log.Logger, samples []*writev2.TimeSeries, label
if err != nil { if err != nil {
return nil, highest, lowest, err return nil, highest, lowest, err
} }
*pBuf = data //*pBuf = data
// snappy uses len() to see if it needs to allocate a new slice. Make the // snappy uses len() to see if it needs to allocate a new slice. Make the
// buffer as long as possible. // buffer as long as possible.
@ -2243,7 +2243,7 @@ func buildV2WriteRequest(logger log.Logger, samples []*writev2.TimeSeries, label
buf = &[]byte{} buf = &[]byte{}
} }
compressed, err = compressPayload(buf, data, enc) compressed, err = compressPayload(buf, (*pBuf)[:size], enc)
if err != nil { if err != nil {
return nil, highest, lowest, err return nil, highest, lowest, err
} }