Browse Source

Add barrier to benchmark writer

This adds a barrier to avoid issues with unfair goroutine scheduling
that causes some fake scrapers to run away from the other ones.
pull/5805/head
Fabian Reinartz 8 years ago
parent
commit
80affd98a8
  1. 2
      cmd/tsdb/Makefile
  2. 71
      cmd/tsdb/main.go

2
cmd/tsdb/Makefile

@ -3,7 +3,7 @@ build:
bench: build
@echo ">> running benchmark"
@./tsdb bench write --out=$(OUT) --metrics=$(NUM_METRICS) testdata.100k
@./tsdb bench write --metrics=$(NUM_METRICS) testdata.100k
@go tool pprof -svg ./tsdb benchout/cpu.prof > benchout/cpuprof.svg
@go tool pprof -svg ./tsdb benchout/mem.prof > benchout/memprof.svg
@go tool pprof -svg ./tsdb benchout/block.prof > benchout/blockprof.svg

71
cmd/tsdb/main.go

@ -138,55 +138,64 @@ func (b *writeBenchmark) ingestScrapes(metrics []model.Metric, scrapeCount int)
var mu sync.Mutex
var total uint64
for len(metrics) > 0 {
l := 1000
if len(metrics) < 1000 {
l = len(metrics)
lbls := make([]labels.Labels, 0, len(metrics))
for _, m := range metrics {
lset := make(labels.Labels, 0, len(m))
for k, v := range m {
lset = append(lset, labels.Label{Name: string(k), Value: string(v)})
}
batch := metrics[:l]
metrics = metrics[l:]
wg.Add(1)
go func(batch []model.Metric) {
n, err := b.ingestScrapesShard(batch, scrapeCount)
if err != nil {
// exitWithError(err)
fmt.Println(" err", err)
sort.Sort(lset)
lbls = append(lbls, lset)
}
for i := 0; i < scrapeCount; i += 25 {
lbls := lbls
for len(lbls) > 0 {
l := 1000
if len(lbls) < 1000 {
l = len(lbls)
}
mu.Lock()
total += n
mu.Unlock()
wg.Done()
}(batch)
batch := lbls[:l]
lbls = lbls[l:]
wg.Add(1)
go func() {
n, err := b.ingestScrapesShard(batch, 25, int64(30000*i))
if err != nil {
// exitWithError(err)
fmt.Println(" err", err)
}
mu.Lock()
total += n
mu.Unlock()
wg.Done()
}()
}
wg.Wait()
}
wg.Wait()
fmt.Println("> total samples:", total)
return nil
}
func (b *writeBenchmark) ingestScrapesShard(metrics []model.Metric, scrapeCount int) (uint64, error) {
func (b *writeBenchmark) ingestScrapesShard(metrics []labels.Labels, scrapeCount int, baset int64) (uint64, error) {
app := b.storage.Appender()
ts := int64(model.Now())
ts := baset
type sample struct {
labels labels.Labels
value int64
}
scrape := make(map[uint64]*sample, len(metrics))
scrape := make([]*sample, 0, len(metrics))
for _, m := range metrics {
lset := make(labels.Labels, 0, len(m))
for k, v := range m {
lset = append(lset, labels.Label{Name: string(k), Value: string(v)})
}
sort.Sort(lset)
scrape[lset.Hash()] = &sample{
labels: lset,
scrape = append(scrape, &sample{
labels: m,
value: 123456789,
}
})
}
total := uint64(0)

Loading…
Cancel
Save