Skip to content

Conversation

@yuchen-db
Copy link
Collaborator

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

Comment on lines 792 to 798
var localWrites, remoteWrites map[endpointReplica]map[string]trackedSeries
var err error
if h.receiverMode == IngestorOnly {
localWrites, remoteWrites, err = h.distributeTimeseriesToReplicas(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.

didn't see difference for the two if-branch?

}

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

Copy link
Collaborator

@jnyi jnyi left a comment

Choose a reason for hiding this comment

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

nice finding, consider to polish it and submit a pr to upstream :)

@yuchen-db yuchen-db force-pushed the yuchen-db/writer-perf branch from 201767f to cf49e95 Compare December 4, 2024 04:39
@hczhu-db
Copy link
Collaborator

hczhu-db commented Dec 4, 2024

Nice work. Have you deployed the change to a dev cluster? Any CPU usage decrease?

Comment on lines +794 to +798
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.

Can you add code comment to explain the difference?

}
localWrites[endpointReplica] = map[string]trackedSeries{tenantHTTP: {seriesIDs: seriesids, timeSeries: timeseries}}
}
fmt.Println("localWrites (IngestorOnly):")
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?

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().

@yuchen-db yuchen-db force-pushed the db_main branch 8 times, most recently from 64fbb3a to 5276dd1 Compare June 5, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants