Skip to content

Commit

Permalink
optimisation: don't copy report stream unnecessarily
Browse files Browse the repository at this point in the history
We don't need to copy from the reader when publishing to just one
destination.
  • Loading branch information
rade committed Jul 21, 2017
1 parent 00ddb51 commit 9e6ecee
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 9e6ecee

Please sign in to comment.