tsdb: use simpler map key to improve exemplar ingest performance (#10111)
* tsdb: fix exemplar benchmarks
Go benchmarks are expected to do an amount of work that varies with
the `b.N` parameter. Previously these benchmarks would report a result
like 0.01 ns/op, which is nonsense.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* tsdb: use simpler map key to improve exemplar perf
Prometheus holds an index of exemplars so it can discard the oldest one
for a series when a new one is added.
Since the keys are not for human eyes, we can use a simpler format
and save the effort of quoting label values.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Exemplars: allocate index map with estimated size
This avoids Go having to re-size the map several times as it grows.
16 exemplars per series is a guess; if it is too low then the map will
be sparse, while if it is too high then the map will have to resize once
or twice.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
require.Equal(t,es.index[l.String()].newest,1,"exemplar was not stored correctly, location of newest exemplar for series in index did not update")
require.True(t,es.exemplars[es.index[l.String()].newest].exemplar.Equals(e2),"exemplar was not stored correctly, expected %+v got: %+v",e2,es.exemplars[es.index[l.String()].newest].exemplar)
require.Equal(t,es.index[string(l.Bytes(nil))].newest,1,"exemplar was not stored correctly, location of newest exemplar for series in index did not update")
require.True(t,es.exemplars[es.index[string(l.Bytes(nil))].newest].exemplar.Equals(e2),"exemplar was not stored correctly, expected %+v got: %+v",e2,es.exemplars[es.index[string(l.Bytes(nil))].newest].exemplar)
require.NoError(t,es.AddExemplar(l,e2),"no error is expected attempting to add duplicate exemplar")