Merge pull request #2736 from weaveworks/optimise-single-client-publish

optimisation: don't copy report stream unnecessarily
This commit is contained in:
Matthias Radestock
2017-07-24 21:23:59 +01:00
committed by GitHub

View File

@@ -166,13 +166,21 @@ func (c *multiClient) Stop() {
// reader, and recreate new readers for each publisher. Note that it will
// publish to one endpoint for each unique ID. Failed publishes don't count.
func (c *multiClient) Publish(r io.Reader) error {
c.mtx.Lock()
defer c.mtx.Unlock()
if len(c.clients) <= 1 { // optimisation
for _, c := range c.clients {
return c.Publish(r)
}
return nil
}
buf, err := ioutil.ReadAll(r)
if err != nil {
return err
}
c.mtx.Lock()
defer c.mtx.Unlock()
errs := []string{}
for _, c := range c.clients {
if err := c.Publish(bytes.NewReader(buf)); err != nil {