Skip to content

Commit

Permalink
Buffer pooling alert post request body buffer (influxdata#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat authored and Nathaniel Cook committed May 16, 2016
1 parent dd41349 commit 3f75670
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,17 @@ func (a *AlertNode) renderMessageAndDetails(id, name string, t time.Time, group
// Alert handlers

func (a *AlertNode) handlePost(post *pipeline.PostHandler, ad *AlertData) {
b, err := json.Marshal(ad)
bodyBuffer := a.bufPool.Get().(*bytes.Buffer)
defer a.bufPool.Put(bodyBuffer)
bodyBuffer.Reset()

err := json.NewEncoder(bodyBuffer).Encode(ad)
if err != nil {
a.logger.Println("E! failed to marshal alert data json", err)
return
}
buf := bytes.NewBuffer(b)
_, err = http.Post(post.URL, "application/json", buf)

_, err = http.Post(post.URL, "application/json", bodyBuffer)
if err != nil {
a.logger.Println("E! failed to POST batch", err)
}
Expand Down

0 comments on commit 3f75670

Please sign in to comment.