influxdb/tsdb/tsm1/engine_delete_prefix.go

274 lines
8.8 KiB
Go
Raw Normal View History

2019-01-08 23:03:34 +00:00
package tsm1
import (
"bytes"
"context"
"fmt"
2019-01-08 23:03:34 +00:00
"math"
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
"strings"
"sync"
"time"
2019-01-08 23:03:34 +00:00
"github.com/influxdata/influxdb/kit/tracing"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/tsdb"
2019-01-08 23:03:34 +00:00
"github.com/influxdata/influxql"
)
// DeletePrefixRange removes all TSM data belonging to a bucket, and removes all index
// and series file data associated with the bucket. The provided time range ensures
// that only bucket data for that range is removed.
func (e *Engine) DeletePrefixRange(rootCtx context.Context, name []byte, min, max int64, pred Predicate) error {
span, ctx := tracing.StartSpanFromContext(rootCtx)
span.LogKV("name_prefix", fmt.Sprintf("%x", name),
"min", time.Unix(0, min), "max", time.Unix(0, max),
"has_pred", pred != nil,
)
defer span.Finish()
2019-01-08 23:03:34 +00:00
// TODO(jeff): we need to block writes to this prefix while deletes are in progress
// otherwise we can end up in a situation where we have staged data in the cache or
// WAL that was deleted from the index, or worse. This needs to happen at a higher
// layer.
// TODO(jeff): ensure the engine is not closed while we're running this. At least
// now we know that the series file or index won't be closed out from underneath
// of us.
2019-01-08 23:03:34 +00:00
// Ensure that the index does not compact away the measurement or series we're
// going to delete before we're done with them.
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "disable index compactions")
2019-01-08 23:03:34 +00:00
e.index.DisableCompactions()
defer e.index.EnableCompactions()
e.index.Wait()
span.Finish()
2019-01-08 23:03:34 +00:00
// Disable and abort running compactions so that tombstones added existing tsm
// files don't get removed. This would cause deleted measurements/series to
// re-appear once the compaction completed. We only disable the level compactions
// so that snapshotting does not stop while writing out tombstones. If it is stopped,
// and writing tombstones takes a long time, writes can get rejected due to the cache
// filling up.
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "disable tsm compactions")
e.disableLevelCompactions(true)
defer e.enableLevelCompactions(true)
span.Finish()
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "disable series file compactions")
e.sfile.DisableCompactions()
defer e.sfile.EnableCompactions()
span.Finish()
2019-01-08 23:03:34 +00:00
// TODO(jeff): are the query language values still a thing?
// Min and max time in the engine are slightly different from the query language values.
if min == influxql.MinTime {
min = math.MinInt64
}
if max == influxql.MaxTime {
max = math.MaxInt64
}
// Run the delete on each TSM file in parallel and keep track of possibly dead keys.
// TODO(jeff): keep a set of keys for each file to avoid contention.
// TODO(jeff): come up with a better way to figure out what keys we need to delete
// from the index.
var possiblyDead struct {
sync.RWMutex
keys map[string]struct{}
}
possiblyDead.keys = make(map[string]struct{})
2019-01-08 23:03:34 +00:00
if err := e.FileStore.Apply(func(r TSMFile) error {
// TODO(edd): tracing this deep down is currently speculative, so I have
// not added the tracing into the TSMReader API.
span, _ := tracing.StartSpanFromContextWithOperationName(rootCtx, "TSMFile delete prefix")
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span.LogKV("file_path", r.Path())
defer span.Finish()
return r.DeletePrefix(name, min, max, pred, func(key []byte) {
possiblyDead.Lock()
possiblyDead.keys[string(key)] = struct{}{}
possiblyDead.Unlock()
})
2019-01-08 23:03:34 +00:00
}); err != nil {
return err
}
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "Cache find delete keys")
span.LogKV("cache_size", e.Cache.Size())
var keysChecked int // For tracing information.
2019-01-08 23:03:34 +00:00
// ApplySerialEntryFn cannot return an error in this invocation.
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
nameStr := string(name)
_ = e.Cache.ApplyEntryFn(func(k string, _ *entry) error {
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
keysChecked++
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
if !strings.HasPrefix(k, nameStr) {
2019-04-29 16:28:34 +00:00
return nil
}
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
// TODO(edd): either use an unsafe conversion to []byte, or add a MatchesString
// method to tsm1.Predicate.
if pred != nil && !pred.Matches([]byte(k)) {
2019-04-29 16:28:34 +00:00
return nil
}
2019-04-29 16:28:34 +00:00
// we have to double check every key in the cache because maybe
// it exists in the index but not yet on disk.
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
possiblyDead.keys[k] = struct{}{}
2019-04-29 16:28:34 +00:00
2019-01-08 23:03:34 +00:00
return nil
})
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span.LogKV("cache_cardinality", keysChecked)
span.Finish()
2019-01-08 23:03:34 +00:00
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
// Delete from the cache (traced in cache).
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
e.Cache.DeleteBucketRange(ctx, nameStr, min, max, pred)
2019-01-08 23:03:34 +00:00
// Now that all of the data is purged, we need to find if some keys are fully deleted
// and if so, remove them from the index.
if err := e.FileStore.Apply(func(r TSMFile) error {
// TODO(edd): tracing this deep down is currently speculative, so I have
// not added the tracing into the Engine API.
span, _ := tracing.StartSpanFromContextWithOperationName(rootCtx, "TSMFile determine fully deleted")
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span.LogKV("file_path", r.Path())
defer span.Finish()
possiblyDead.RLock()
defer possiblyDead.RUnlock()
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
var keysChecked int
iter := r.Iterator(name)
for i := 0; iter.Next(); i++ {
key := iter.Key()
if !bytes.HasPrefix(key, name) {
break
}
2019-04-29 16:28:34 +00:00
if pred != nil && !pred.Matches(key) {
continue
}
// TODO(jeff): benchmark the locking here.
if i%1024 == 0 { // allow writes to proceed.
possiblyDead.RUnlock()
possiblyDead.RLock()
}
if _, ok := possiblyDead.keys[string(key)]; ok {
possiblyDead.RUnlock()
possiblyDead.Lock()
delete(possiblyDead.keys, string(key))
possiblyDead.Unlock()
possiblyDead.RLock()
}
}
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span.LogKV("keys_checked", keysChecked)
return iter.Err()
}); err != nil {
return err
}
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "Cache find delete keys")
span.LogKV("cache_size", e.Cache.Size())
keysChecked = 0
// ApplySerialEntryFn cannot return an error in this invocation.
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
_ = e.Cache.ApplyEntryFn(func(k string, _ *entry) error {
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
keysChecked++
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
if !strings.HasPrefix(k, nameStr) {
2019-04-29 16:28:34 +00:00
return nil
}
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
// TODO(edd): either use an unsafe conversion to []byte, or add a MatchesString
// method to tsm1.Predicate.
if pred != nil && !pred.Matches([]byte(k)) {
2019-04-29 16:28:34 +00:00
return nil
}
perf(storage): reduce allocations when deleting from cache When deleting from the cache, each cache key must be checked to determine if it matches the prefix we're deleting. Since the keys are stored as strings in the cache (map keys) there were a lot of allocations happening because `applySerial` expects `[]byte` keys. It's beneficial to reduce allocations by refacting `applySerial` to work on strings. Whilst some allocations now have to happen the other way (string -> []byte), they only happen if we actually need to delete the key from the cache. Most of the keys don't get deleted so it's better doing it this way. Performance on the benchmark from the previous commit improved by ~40-50%. name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 102ms ±11% 59ms ± 3% -41.95% (p=0.000 n=10+8) Engine_DeletePrefixRange_Cache/not_exists-24 97.1ms ± 4% 45.0ms ± 1% -53.66% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 25.5MB ± 1% 3.1MB ± 2% -87.83% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 23.9MB ± 1% 0.1MB ±86% -99.65% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 305k ± 1% 28k ± 1% -90.77% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 299k ± 1% 1k ±63% -99.74% (p=0.000 n=9+10) Raw benchmarks on a 24T/32GB/NVME machine are as follows: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 50379720 ns/op 3054106 B/op 27859 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 57326032 ns/op 3124764 B/op 28217 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 58943855 ns/op 3162146 B/op 28527 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 60565115 ns/op 3138811 B/op 28176 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 59775969 ns/op 3087910 B/op 27921 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59530451 ns/op 3120986 B/op 28207 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59185532 ns/op 3113066 B/op 28302 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59295867 ns/op 3100832 B/op 28108 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 300 59599776 ns/op 3100686 B/op 28113 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 200 62065907 ns/op 3048527 B/op 27879 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44979062 ns/op 123026 B/op 1244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44733344 ns/op 52650 B/op 479 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44534180 ns/op 35119 B/op 398 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45179881 ns/op 105256 B/op 706 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44918964 ns/op 47426 B/op 621 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45000465 ns/op 63164 B/op 564 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45332999 ns/op 117008 B/op 1146 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45652342 ns/op 66221 B/op 616 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 45083957 ns/op 154354 B/op 1143 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 300 44560228 ns/op 65024 B/op 724 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 1690.583s
2019-08-30 15:41:47 +00:00
delete(possiblyDead.keys, k)
return nil
})
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span.LogKV("cache_cardinality", keysChecked)
span.Finish()
if len(possiblyDead.keys) > 0 {
buf := make([]byte, 1024)
// TODO(jeff): all of these methods have possible errors which opens us to partial
// failure scenarios. we need to either ensure that partial errors here are ok or
// do something to fix it.
// TODO(jeff): it's also important that all of the deletes happen atomically with
// the deletes of the data in the tsm files.
// In this case the entire measurement (bucket) can be removed from the index.
2019-04-29 16:28:34 +00:00
if min == math.MinInt64 && max == math.MaxInt64 && pred == nil {
// The TSI index and Series File do not store series data in escaped form.
name = models.UnescapeMeasurement(name)
// Build up a set of series IDs that we need to remove from the series file.
set := tsdb.NewSeriesIDSet()
itr, err := e.index.MeasurementSeriesIDIterator(name)
if err != nil {
return err
}
var elem tsdb.SeriesIDElem
for elem, err = itr.Next(); err != nil; elem, err = itr.Next() {
if elem.SeriesID.IsZero() {
break
}
set.AddNoLock(elem.SeriesID)
}
if err != nil {
return err
} else if err := itr.Close(); err != nil {
return err
}
// Remove the measurement from the index before the series file.
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "TSI drop measurement")
span.LogKV("measurement_name", fmt.Sprintf("%x", name))
if err := e.index.DropMeasurement(name); err != nil {
return err
}
span.Finish()
// Iterate over the series ids we previously extracted from the index
// and remove from the series file.
perf(storage): reduce amount of tracing In a previous PR I added some tracing to help investigate delete performance within the cache. Ironically this makes performance significantly worse when you have a very high cardinality cache. This keeps the main benefits of the tracing, but reduces the number of spans created. The remaining spans are smarter with context, and include useful information about the size of the operation being traced. Performance on a benchmark shows a significant improvement: name old time/op new time/op delta Engine_DeletePrefixRange_Cache/exists-24 262ms ± 6% 113ms ± 8% -57.06% (p=0.000 n=10+10) Engine_DeletePrefixRange_Cache/not_exists-24 266ms ± 4% 96ms ± 2% -64.09% (p=0.000 n=8+10) name old alloc/op new alloc/op delta Engine_DeletePrefixRange_Cache/exists-24 62.7MB ± 0% 29.6MB ± 1% -52.82% (p=0.000 n=9+10) Engine_DeletePrefixRange_Cache/not_exists-24 59.2MB ± 0% 24.3MB ± 2% -59.03% (p=0.000 n=8+10) name old allocs/op new allocs/op delta Engine_DeletePrefixRange_Cache/exists-24 711k ± 0% 334k ± 0% -53.07% (p=0.000 n=9+8) Engine_DeletePrefixRange_Cache/not_exists-24 700k ± 0% 302k ± 1% -56.79% (p=0.000 n=8+10) Raw benchmarks on a 24T/32GB/Nvme machine: goos: linux goarch: amd64 pkg: github.com/influxdata/influxdb/tsdb/tsm1 BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 104851012 ns/op 29442514 B/op 333599 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 107838824 ns/op 29485649 B/op 334369 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 108020671 ns/op 29443324 B/op 333610 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 106507506 ns/op 29977931 B/op 338597 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 116393032 ns/op 29443516 B/op 333614 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 112581877 ns/op 29691455 B/op 334699 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 119833106 ns/op 29444712 B/op 333625 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 100 113851895 ns/op 29921119 B/op 337419 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 121735395 ns/op 29445551 B/op 333634 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/exists-24 50 115387319 ns/op 29444513 B/op 333627 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94474658 ns/op 24696698 B/op 306702 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 94767020 ns/op 24004763 B/op 300066 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97869523 ns/op 24556560 B/op 305827 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93916119 ns/op 24172163 B/op 301244 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96591891 ns/op 24006021 B/op 300081 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 93521244 ns/op 24266467 B/op 303190 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95419569 ns/op 24006501 B/op 300087 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 96694570 ns/op 24521126 B/op 306041 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 95075965 ns/op 24299409 B/op 301649 allocs/op BenchmarkEngine_DeletePrefixRange_Cache/not_exists-24 100 97182864 ns/op 24007644 B/op 300101 allocs/op PASS ok github.com/influxdata/influxdb/tsdb/tsm1 490.287s
2019-08-30 10:48:58 +00:00
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "SFile Delete Series IDs")
span.LogKV("measurement_name", fmt.Sprintf("%x", name), "series_id_set_size", set.Cardinality())
set.ForEachNoLock(func(id tsdb.SeriesID) {
if err = e.sfile.DeleteSeriesID(id); err != nil {
return
}
})
span.Finish()
return err
}
// This is the slow path, when not dropping the entire bucket (measurement)
span, _ = tracing.StartSpanFromContextWithOperationName(rootCtx, "TSI/SFile Delete keys")
span.LogKV("measurement_name", fmt.Sprintf("%x", name), "keys_to_delete", len(possiblyDead.keys))
for key := range possiblyDead.keys {
// TODO(jeff): ugh reduce copies here
keyb := []byte(key)
2019-01-09 17:56:10 +00:00
keyb, _ = SeriesAndFieldFromCompositeKey(keyb)
name, tags := models.ParseKeyBytes(keyb)
sid := e.sfile.SeriesID(name, tags, buf)
if sid.IsZero() {
continue
}
if err := e.index.DropSeries(sid, keyb, true); err != nil {
return err
}
if err := e.sfile.DeleteSeriesID(sid); err != nil {
return err
}
}
span.Finish()
}
2019-01-08 23:03:34 +00:00
return nil
}