Skip to content

Commit

Permalink
Merge pull request #2736 from weaveworks/optimise-single-client-publish
Browse files Browse the repository at this point in the history
optimisation: don't copy report stream unnecessarily
  • Loading branch information
rade authored Jul 24, 2017
2 parents 3c16c41 + 9e6ecee commit 09b3026
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions probe/appclient/multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 09b3026

Please sign in to comment.