|
|
|
@ -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) |
|
|
|
|
|
|
|
|
|