Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
// Copyright 2013 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
package metric
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-02-26 14:47:25 -08:00
|
|
|
"encoding/binary"
|
2013-06-25 05:02:27 -07:00
|
|
|
"fmt"
|
2014-02-26 14:47:25 -08:00
|
|
|
"math"
|
2013-06-25 05:02:27 -07:00
|
|
|
"sort"
|
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
)
|
|
|
|
|
2014-03-11 06:07:48 -07:00
|
|
|
const (
|
|
|
|
// sampleSize is the number of bytes per sample in marshalled format.
|
|
|
|
sampleSize = 16
|
|
|
|
// formatVersion is used as a version marker in the marshalled format.
|
|
|
|
formatVersion = 1
|
|
|
|
// formatVersionSize is the number of bytes used by the serialized formatVersion.
|
|
|
|
formatVersionSize = 1
|
|
|
|
)
|
2014-02-26 14:47:25 -08:00
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// MarshalJSON implements json.Marshaler.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (s SamplePair) MarshalJSON() ([]byte, error) {
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
return []byte(fmt.Sprintf("{\"Value\": \"%f\", \"Timestamp\": %d}", s.Value, s.Timestamp)), nil
|
2013-06-25 05:02:27 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// SamplePair pairs a SampleValue with a Timestamp.
|
2013-06-25 05:02:27 -07:00
|
|
|
type SamplePair struct {
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
Timestamp clientmodel.Timestamp
|
2014-02-26 14:47:25 -08:00
|
|
|
Value clientmodel.SampleValue
|
2013-06-25 05:02:27 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Equal returns true if this SamplePair and o have equal Values and equal
|
|
|
|
// Timestamps.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (s *SamplePair) Equal(o *SamplePair) bool {
|
|
|
|
if s == o {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SamplePair) String() string {
|
|
|
|
return fmt.Sprintf("SamplePair at %s of %s", s.Timestamp, s.Value)
|
|
|
|
}
|
|
|
|
|
2014-03-10 09:55:17 -07:00
|
|
|
// Values is a sortable slice of SamplePairs (as in: it implements
|
2014-02-14 10:36:27 -08:00
|
|
|
// sort.Interface). Sorting happens by Timestamp.
|
2014-03-10 09:55:17 -07:00
|
|
|
type Values []SamplePair
|
2013-06-25 05:02:27 -07:00
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Len implements sort.Interface.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (v Values) Len() int {
|
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Less implements sort.Interface.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (v Values) Less(i, j int) bool {
|
|
|
|
return v[i].Timestamp.Before(v[j].Timestamp)
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Swap implements sort.Interface.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (v Values) Swap(i, j int) {
|
|
|
|
v[i], v[j] = v[j], v[i]
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Equal returns true if these Values are of the same length as o, and each
|
|
|
|
// value is equal to the corresponding value in o (i.e. at the same index).
|
2013-06-25 05:02:27 -07:00
|
|
|
func (v Values) Equal(o Values) bool {
|
|
|
|
if len(v) != len(o) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, expected := range v {
|
2014-03-10 09:55:17 -07:00
|
|
|
if !expected.Equal(&o[i]) {
|
2013-06-25 05:02:27 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstTimeAfter indicates whether the first sample of a set is after a given
|
|
|
|
// timestamp.
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
func (v Values) FirstTimeAfter(t clientmodel.Timestamp) bool {
|
2013-06-25 05:02:27 -07:00
|
|
|
return v[0].Timestamp.After(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastTimeBefore indicates whether the last sample of a set is before a given
|
|
|
|
// timestamp.
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
func (v Values) LastTimeBefore(t clientmodel.Timestamp) bool {
|
2013-06-25 05:02:27 -07:00
|
|
|
return v[len(v)-1].Timestamp.Before(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InsideInterval indicates whether a given range of sorted values could contain
|
|
|
|
// a value for a given time.
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
func (v Values) InsideInterval(t clientmodel.Timestamp) bool {
|
2013-06-25 05:02:27 -07:00
|
|
|
switch {
|
|
|
|
case v.Len() == 0:
|
|
|
|
return false
|
|
|
|
case t.Before(v[0].Timestamp):
|
|
|
|
return false
|
|
|
|
case !v[v.Len()-1].Timestamp.Before(t):
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TruncateBefore returns a subslice of the original such that extraneous
|
|
|
|
// samples in the collection that occur before the provided time are
|
|
|
|
// dropped. The original slice is not mutated
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
func (v Values) TruncateBefore(t clientmodel.Timestamp) Values {
|
2013-06-25 05:02:27 -07:00
|
|
|
index := sort.Search(len(v), func(i int) bool {
|
|
|
|
timestamp := v[i].Timestamp
|
|
|
|
|
|
|
|
return !timestamp.Before(t)
|
|
|
|
})
|
|
|
|
|
|
|
|
return v[index:]
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// ToSampleKey returns the SampleKey for these Values.
|
2013-06-25 05:02:27 -07:00
|
|
|
func (v Values) ToSampleKey(f *clientmodel.Fingerprint) *SampleKey {
|
|
|
|
return &SampleKey{
|
|
|
|
Fingerprint: f,
|
|
|
|
FirstTimestamp: v[0].Timestamp,
|
|
|
|
LastTimestamp: v[len(v)-1].Timestamp,
|
|
|
|
SampleCount: uint32(len(v)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Values) String() string {
|
|
|
|
buffer := bytes.Buffer{}
|
|
|
|
|
|
|
|
fmt.Fprintf(&buffer, "[")
|
|
|
|
for i, value := range v {
|
|
|
|
fmt.Fprintf(&buffer, "%d. %s", i, value)
|
|
|
|
if i != len(v)-1 {
|
|
|
|
fmt.Fprintf(&buffer, "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&buffer, "]")
|
|
|
|
|
|
|
|
return buffer.String()
|
|
|
|
}
|
|
|
|
|
2014-02-26 14:47:25 -08:00
|
|
|
// marshal marshals a group of samples for being written to disk.
|
|
|
|
func (v Values) marshal() []byte {
|
2014-03-11 06:07:48 -07:00
|
|
|
buf := make([]byte, formatVersionSize+len(v)*sampleSize)
|
|
|
|
buf[0] = formatVersion
|
2014-02-26 14:47:25 -08:00
|
|
|
for i, val := range v {
|
2014-03-11 06:07:48 -07:00
|
|
|
offset := formatVersionSize + i*sampleSize
|
2014-02-26 14:47:25 -08:00
|
|
|
binary.LittleEndian.PutUint64(buf[offset:], uint64(val.Timestamp.Unix()))
|
|
|
|
binary.LittleEndian.PutUint64(buf[offset+8:], math.Float64bits(float64(val.Value)))
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshalValues decodes marshalled samples and returns them as Values.
|
|
|
|
func unmarshalValues(buf []byte) Values {
|
2014-03-11 06:07:48 -07:00
|
|
|
n := len(buf) / sampleSize
|
2014-02-26 14:47:25 -08:00
|
|
|
// Setting the value of a given slice index is around 15% faster than doing
|
|
|
|
// an append, even if the slice already has the required capacity. For this
|
|
|
|
// reason, we already set the full target length here.
|
|
|
|
v := make(Values, n)
|
|
|
|
|
2014-03-11 06:07:48 -07:00
|
|
|
if buf[0] != formatVersion {
|
|
|
|
panic("unsupported format version")
|
|
|
|
}
|
2014-02-26 14:47:25 -08:00
|
|
|
for i := 0; i < n; i++ {
|
2014-03-11 06:07:48 -07:00
|
|
|
offset := formatVersionSize + i*sampleSize
|
2014-03-10 09:55:17 -07:00
|
|
|
v[i].Timestamp = clientmodel.TimestampFromUnix(int64(binary.LittleEndian.Uint64(buf[offset:])))
|
|
|
|
v[i].Value = clientmodel.SampleValue(math.Float64frombits(binary.LittleEndian.Uint64(buf[offset+8:])))
|
2013-06-25 05:02:27 -07:00
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// SampleSet is Values with a Metric attached.
|
2013-06-25 05:02:27 -07:00
|
|
|
type SampleSet struct {
|
|
|
|
Metric clientmodel.Metric
|
|
|
|
Values Values
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// Interval describes the inclusive interval between two Timestamps.
|
2013-06-25 05:02:27 -07:00
|
|
|
type Interval struct {
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
OldestInclusive clientmodel.Timestamp
|
|
|
|
NewestInclusive clientmodel.Timestamp
|
2013-06-25 05:02:27 -07:00
|
|
|
}
|