Skip to content

Commit

Permalink
Fix concurrent map access
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Mar 10, 2016
1 parent db9d403 commit 11424a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stress/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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()
}
}

Expand Down
2 changes: 2 additions & 0 deletions stress/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"strings"
"sync"
)

// Config is a struct for the Stress test configuration
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 11424a8

Please sign in to comment.