From 9e6ecee37d910e8023ac8afbbf350e4b95ea9b24 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 21 Jul 2017 17:56:08 +0100 Subject: [PATCH] optimisation: don't copy report stream unnecessarily We don't need to copy from the reader when publishing to just one destination. --- probe/appclient/multi_client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/probe/appclient/multi_client.go b/probe/appclient/multi_client.go index f741c3129d..2eb7bf556e 100644 --- a/probe/appclient/multi_client.go +++ b/probe/appclient/multi_client.go @@ -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 {