mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2025-09-17 22:14:31 +02:00
Reduce gaps/rewrites in the same cell with offset
A new buffer remembers the timestamp of the first write. Instead of cutting of cells relative to that time, have a little "time buffer" so that rewriting the same cell twice happens less often.
This commit is contained in:
@@ -59,7 +59,13 @@ func (b *buffer) write(ts int64, value Float) (*buffer, error) {
|
||||
return nil, errors.New("cannot write value to buffer from past")
|
||||
}
|
||||
|
||||
idx := int((ts - b.start) / b.frequency)
|
||||
// When a new buffer is created, it starts at ts. If we would
|
||||
// use the same index calculation as for a read here, even a very
|
||||
// slight drift in the timestamps of values will cause cases where
|
||||
// a cell is re-written. Adding any value smaller than half the frequency
|
||||
// here creates a time buffer around the cutoff from one cell to the next
|
||||
// with the same semantics as before.
|
||||
idx := int((ts - b.start + (b.frequency / 3)) / b.frequency)
|
||||
if idx >= cap(b.data) {
|
||||
newbuf := newBuffer(ts, b.frequency)
|
||||
newbuf.prev = b
|
||||
|
Reference in New Issue
Block a user