mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
optimisation: don't copy report stream unnecessarily
We don't need to copy from the reader when publishing to just one destination.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user