-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
receive: Optimized receive; fixed long term overallocation #3334
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e09c413
receive: Added benchmark for writes.
bwplotka 65aa6c1
Optimized write: AddFast and debug prints.
bwplotka 1db1615
Removed ZLabels from promb.
bwplotka 153636f
Optimized hash.
bwplotka 9f0ec87
Reduced allocs on write append errors.
bwplotka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,10 +4,11 @@ | |||||
package receive | ||||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"context" | ||||||
"crypto/tls" | ||||||
"fmt" | ||||||
"io/ioutil" | ||||||
"io" | ||||||
stdlog "log" | ||||||
"net" | ||||||
"net/http" | ||||||
|
@@ -282,13 +283,17 @@ func (h *Handler) receiveHTTP(w http.ResponseWriter, r *http.Request) { | |||||
span, ctx := tracing.StartSpan(r.Context(), "receive_http") | ||||||
defer span.Finish() | ||||||
|
||||||
compressed, err := ioutil.ReadAll(r.Body) | ||||||
compressed := &bytes.Buffer{} | ||||||
if r.ContentLength >= 0 { | ||||||
compressed.Grow(int(r.ContentLength)) | ||||||
} | ||||||
_, err := io.Copy(compressed, r.Body) | ||||||
if err != nil { | ||||||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
|
||||||
reqBuf, err := snappy.Decode(nil, compressed) | ||||||
reqBuf, err := snappy.Decode(nil, compressed.Bytes()) | ||||||
if err != nil { | ||||||
level.Error(h.logger).Log("msg", "snappy decode error", "err", err) | ||||||
http.Error(w, err.Error(), http.StatusBadRequest) | ||||||
|
@@ -314,6 +319,10 @@ func (h *Handler) receiveHTTP(w http.ResponseWriter, r *http.Request) { | |||||
if len(tenant) == 0 { | ||||||
tenant = h.options.DefaultTenantID | ||||||
} | ||||||
if len(tenant) == 0 { | ||||||
http.Error(w, "no tenant ID supplied", http.StatusBadRequest) | ||||||
return | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between this if and line 319? |
||||||
|
||||||
err = h.handleRequest(ctx, rep, tenant, &wreq) | ||||||
switch err { | ||||||
|
@@ -401,9 +410,10 @@ func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas ma | |||||
} | ||||||
}() | ||||||
|
||||||
logger := log.With(h.logger, "tenant", tenant) | ||||||
// Avoid log.With extra allocations for rare log lines. | ||||||
logTags := []interface{}{"tenant", tenant} | ||||||
if id, ok := middleware.RequestIDFromContext(pctx); ok { | ||||||
logger = log.With(logger, "request-id", id) | ||||||
logTags = append(logTags, "request-id", id) | ||||||
} | ||||||
|
||||||
ec := make(chan error) | ||||||
|
@@ -524,7 +534,7 @@ func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas ma | |||||
b.attempt++ | ||||||
dur := h.expBackoff.ForAttempt(b.attempt) | ||||||
b.nextAllowed = time.Now().Add(dur) | ||||||
level.Debug(h.logger).Log("msg", "target unavailable backing off", "for", dur) | ||||||
level.Debug(h.logger).Log(append(logTags, "msg", "msg", "target unavailable backing off", "for", dur)...) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} else { | ||||||
h.peerStates[endpoint] = &retryState{nextAllowed: time.Now().Add(h.expBackoff.ForAttempt(0))} | ||||||
} | ||||||
|
@@ -553,7 +563,7 @@ func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas ma | |||||
go func() { | ||||||
for err := range ec { | ||||||
if err != nil { | ||||||
level.Debug(logger).Log("msg", "request failed, but not needed to achieve quorum", "err", err) | ||||||
level.Debug(h.logger).Log(append(logTags, "msg", "request failed, but not needed to achieve quorum", "err", err)...) | ||||||
} | ||||||
} | ||||||
}() | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious how much does it optimize? It is not very clear compared to a simple one line
ioutil.Readall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will comment (: