m3db writetagged应该并发做,不然会导致transfer rpc变慢 (#514)
* m3db writetagged应该并发做,不然会导致transfer rpc变慢 * go func指针传参问题
This commit is contained in:
parent
f590194fba
commit
6b1e432f6d
|
@ -3,6 +3,7 @@ package m3db
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/didi/nightingale/src/common/dataobj"
|
"github.com/didi/nightingale/src/common/dataobj"
|
||||||
|
@ -89,23 +90,31 @@ func (p *Client) Push2Queue(items []*dataobj.MetricValue) {
|
||||||
logger.Errorf("unable to get m3db session: %s", err)
|
logger.Errorf("unable to get m3db session: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var errCnt int32
|
||||||
errCnt := 0
|
var (
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if err := session.WriteTagged(
|
wg.Add(1)
|
||||||
p.namespaceID,
|
go func(dm *dataobj.MetricValue) {
|
||||||
mvID(item),
|
err := session.WriteTagged(
|
||||||
ident.NewTagsIterator(mvTags(item)),
|
p.namespaceID,
|
||||||
time.Unix(item.Timestamp, 0),
|
mvID(dm),
|
||||||
item.Value,
|
ident.NewTagsIterator(mvTags(dm)),
|
||||||
xtime.Second,
|
time.Unix(dm.Timestamp, 0),
|
||||||
nil,
|
dm.Value,
|
||||||
); err != nil {
|
xtime.Second,
|
||||||
logger.Errorf("unable to writeTagged: %s", err)
|
nil)
|
||||||
errCnt++
|
if err != nil {
|
||||||
}
|
logger.Errorf("unable to writeTagged: %s", err)
|
||||||
|
atomic.AddInt32(&errCnt, 1)
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}(item)
|
||||||
|
|
||||||
}
|
}
|
||||||
stats.Counter.Set("m3db.queue.err", errCnt)
|
wg.Wait()
|
||||||
|
stats.Counter.Set("m3db.queue.err", int(errCnt))
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryData: || (|| endpoints...) (&& tags...)
|
// QueryData: || (|| endpoints...) (&& tags...)
|
||||||
|
|
Loading…
Reference in New Issue