Fix concurrent map access

pull/5975/head
Michael Desa 2016-03-10 10:06:08 -08:00
parent db9d403fd1
commit 11424a889f
2 changed files with 6 additions and 0 deletions

View File

@ -659,7 +659,9 @@ func (o *outputConfig) HTTPHandler(method string) func(r <-chan response, rt *Ti
Precision: "ns",
})
for p := range r {
o.mu.Lock()
tags := o.tags
o.mu.Unlock()
tags["method"] = method
fields := map[string]interface{}{
"response_time": float64(p.Timer.Elapsed()),
@ -668,10 +670,12 @@ func (o *outputConfig) HTTPHandler(method string) func(r <-chan response, rt *Ti
bp.AddPoint(pt)
if len(bp.Points())%1000 == 0 && len(bp.Points()) != 0 {
c.Write(bp)
o.mu.Lock()
bp, _ = client.NewBatchPoints(client.BatchPointsConfig{
Database: o.database,
Precision: "ns",
})
o.mu.Unlock()
}
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"strings"
"sync"
)
// Config is a struct for the Stress test configuration
@ -102,6 +103,7 @@ type outputConfig struct {
tags map[string]string
addr string
database string
mu sync.Mutex
}
func (t *outputConfig) SetParams(addr, db string) {