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

Job queue #247

Merged
merged 8 commits into from
Jun 7, 2022
Merged

Job queue #247

merged 8 commits into from
Jun 7, 2022

Conversation

pstibrany
Copy link
Member

This PR reimplements chan chunkWriteJob with custom buffered queue that should use less memory, because it doesn't preallocate entire buffer for maximum queue size at once. Instead it allocates individual "segments" with smaller size.

As elements are added to the queue, they fill individual segments. When elements are removed from the queue (and segments), empty segments can be thrown away. This doesn't change memory usage of the queue when it's full, but should decrease its memory footprint when it's empty (queue will keep max 1 segment in such case).

(Going to test the change in our dev cluster)

@pstibrany pstibrany requested review from replay, codesome and pracucci and removed request for replay June 3, 2022 13:51
tsdb/chunks/queue.go Outdated Show resolved Hide resolved
tsdb/chunks/queue.go Outdated Show resolved Hide resolved
tsdb/chunks/queue.go Outdated Show resolved Hide resolved
@pstibrany
Copy link
Member Author

@replay Thanks for your review. I've addressed your comments. I've also modified implementation to avoid using len and cap and use two indexes instead (index of next read for pop, and next write for push), I think it makes code easier to read and understand.

I would appreciate if you had a chance to look at the PR again.

Added test that pop() returns all elements from closed queue.
Copy link
Contributor

@replay replay left a comment

Choose a reason for hiding this comment

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

This looks great, thanks!

@pstibrany
Copy link
Member Author

Thanks for your review @replay!

@pstibrany pstibrany merged commit 1e2d2fb into main Jun 7, 2022
pstibrany added a commit to grafana/mimir that referenced this pull request Jun 7, 2022
Included changes:

grafana/mimir-prometheus#131
grafana/mimir-prometheus#247

These should result is lower memory usage by chunk mapper.
Comment on lines 252 to 253
// When the queue is full and blocked on the writer the chunkRefMap has one more job than the cap of the jobCh
// because one job is currently being processed and blocked in the writer.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment should be updated too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think comment in queueSize() needs to be updated too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, thanks for catching this. Will send new PR.

pstibrany added a commit to grafana/mimir that referenced this pull request Jun 8, 2022
Included changes:

grafana/mimir-prometheus#131
grafana/mimir-prometheus#247

These should result is lower memory usage by chunk mapper.
@pstibrany pstibrany mentioned this pull request Jun 8, 2022
pstibrany added a commit to grafana/mimir that referenced this pull request Jun 8, 2022
Included changes:

grafana/mimir-prometheus#131
grafana/mimir-prometheus#247

These should result is lower memory usage by chunk mapper.
pstibrany added a commit to grafana/mimir that referenced this pull request Jun 8, 2022
* Update Prometheus with async chunk mapper changes.

Included changes:

grafana/mimir-prometheus#131
grafana/mimir-prometheus#247

These result is lower memory usage by chunk mapper.

Signed-off-by: Peter Štibraný <[email protected]>
@pstibrany
Copy link
Member Author

Sent to upstream Prometheus as prometheus/prometheus#10874.

@pstibrany pstibrany deleted the job-queue branch November 28, 2022 08:16
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.

3 participants