-
Notifications
You must be signed in to change notification settings - Fork 7
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 perf #110
base: db_main
Are you sure you want to change the base?
receive perf #110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -789,7 +789,13 @@ | |
} | ||
requestLogger := log.With(h.logger, logTags...) | ||
|
||
localWrites, remoteWrites, err := h.distributeTimeseriesToReplicas(params.tenant, params.replicas, params.writeRequest.Timeseries) | ||
var localWrites, remoteWrites map[endpointReplica]map[string]trackedSeries | ||
var err error | ||
if h.receiverMode == IngestorOnly { | ||
localWrites, remoteWrites, err = h.distributeTimeseriesToReplicasIngestorOnly(params.tenant, params.replicas, params.writeRequest.Timeseries) | ||
} else { | ||
localWrites, remoteWrites, err = h.distributeTimeseriesToReplicas(params.tenant, params.replicas, params.writeRequest.Timeseries) | ||
} | ||
Comment on lines
+794
to
+798
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. Can you add code comment to explain the difference? |
||
if err != nil { | ||
level.Error(requestLogger).Log("msg", "failed to distribute timeseries to replicas", "err", err) | ||
return stats, err | ||
|
@@ -863,6 +869,33 @@ | |
} | ||
} | ||
|
||
func printMap(data map[endpointReplica]map[string]trackedSeries) { | ||
for key, innerMap := range data { | ||
fmt.Printf("Endpoint: %s, CapNProtoAddress: %s, AZ: %s, Replica: %d\n", key.endpoint.Address, key.endpoint.CapNProtoAddress, key.endpoint.AZ, key.replica) | ||
for strKey, series := range innerMap { | ||
fmt.Printf(" Key: %s\n", strKey) | ||
fmt.Printf(" SeriesIDs: %v\n", series.seriesIDs) | ||
fmt.Printf(" TimeSeries length: %d\n", len(series.timeSeries)) | ||
} | ||
} | ||
} | ||
|
||
func (h *Handler) distributeTimeseriesToReplicasIngestorOnly(tenantHTTP string, replicas []uint64, timeseries []prompb.TimeSeries) (map[endpointReplica]map[string]trackedSeries, map[endpointReplica]map[string]trackedSeries, error) { | ||
remoteWrites := make(map[endpointReplica]map[string]trackedSeries) | ||
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. actually should avoid allocation if remote writes are empty, you can consider to reuse a static map for ingestor |
||
localWrites := make(map[endpointReplica]map[string]trackedSeries, len(replicas)) | ||
for _, rn := range replicas { | ||
endpointReplica := endpointReplica{endpoint: Endpoint{Address: h.options.Endpoint, CapNProtoAddress: h.options.Endpoint}, replica: rn} | ||
seriesids := make([]int, len(timeseries), len(timeseries)) | ||
for i := range timeseries { | ||
seriesids[i] = i | ||
} | ||
localWrites[endpointReplica] = map[string]trackedSeries{tenantHTTP: {seriesIDs: seriesids, timeSeries: timeseries}} | ||
} | ||
fmt.Println("localWrites (IngestorOnly):") | ||
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. Are those |
||
printMap(localWrites) | ||
return localWrites, remoteWrites, nil | ||
} | ||
|
||
// distributeTimeseriesToReplicas distributes the given timeseries from the tenant to different endpoints in a manner | ||
// that achieves the replication factor indicated by replicas. | ||
// The first return value are the series that should be written to the local node. The second return value are the | ||
|
@@ -928,6 +961,10 @@ | |
if h.receiverMode == IngestorOnly && len(remoteWrites) > 0 { | ||
panic("ingestor only mode should not have any remote writes") | ||
} | ||
fmt.Println("localWrites (both):") | ||
printMap(localWrites) | ||
fmt.Println("remoteWrites (both):") | ||
printMap(remoteWrites) | ||
return localWrites, remoteWrites, nil | ||
} | ||
|
||
|
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.
distributeTimeseriesToReplicas()
can be optimized further by removinglocalWrites
related logic. I'd suggest creating a new function,distributeTimeseriesToReplicasRouterOnly()
.