Skip to content
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

Open
wants to merge 3 commits into
base: db_main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

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 removing localWrites related logic. I'd suggest creating a new function, distributeTimeseriesToReplicasRouterOnly().

}
Comment on lines +794 to +798
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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):")

Check failure on line 894 in pkg/receive/handler.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Println" from package "fmt" shouldn't be used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those fmt.Print*() only for your debugging? Remove them?

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
Expand Down Expand Up @@ -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):")

Check failure on line 964 in pkg/receive/handler.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Println" from package "fmt" shouldn't be used
printMap(localWrites)
fmt.Println("remoteWrites (both):")

Check failure on line 966 in pkg/receive/handler.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Println" from package "fmt" shouldn't be used
printMap(remoteWrites)
return localWrites, remoteWrites, nil
}

Expand Down
Loading