Skip to content

Improve downsample performance by buffering docids and do bulk processing. #124477

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

Merged
merged 5 commits into from
Mar 13, 2025

Conversation

martijnvg
Copy link
Member

No description provided.

@martijnvg martijnvg added >enhancement :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data v8.18.1 v8.19.0 v9.0.1 v9.1.0 labels Mar 10, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @martijnvg, I've created a changelog YAML for you.

@martijnvg martijnvg force-pushed the downsample_bulk_processing branch 2 times, most recently from ff95cf7 to 0f70d99 Compare March 11, 2025 10:58
@martijnvg
Copy link
Member Author

The result without this change downsampling tsdb index to 1m interval buckets:

[2025-03-11T12:13:51,906][INFO ][o.e.x.d.DownsampleShardIndexer] [runTask-0] Shard [[tsdb][0]] successfully sent [116633696], received source doc [7089492], indexed downsampled doc [7089492], failed [0], took [2.8m]

The result without this change downsampling tsdb index to 1h interval buckets:

[2025-03-11T12:16:53,664][INFO ][o.e.x.d.DownsampleShardIndexer] [runTask-0] Shard [[tsdb][0]] successfully sent [116633696], received source doc [229256], indexed downsampled doc [229256], failed [0], took [1.5m]

The result with this change downsampling tsdb index to 1m interval buckets:

[2025-03-11T12:07:38,856][INFO ][o.e.x.d.DownsampleShardIndexer] [runTask-0] Shard [[tsdb][0]] successfully sent [116633696], received source doc [7089492], indexed downsampled doc [7089492], failed [0], took [2.4m]

The result with this change downsampling tsdb index to 1h interval buckets:

[2025-03-11T12:09:31,252][INFO ][o.e.x.d.DownsampleShardIndexer] [runTask-0] Shard [[tsdb][0]] successfully sent [116633696], received source doc [229256], indexed downsampled doc [229256], failed [0], took [56.6s]

@martijnvg martijnvg force-pushed the downsample_bulk_processing branch from 0f70d99 to 04c909d Compare March 11, 2025 12:08
@martijnvg martijnvg marked this pull request as ready for review March 11, 2025 12:08
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@martijnvg martijnvg added the auto-backport Automatically create backport pull requests when merged label Mar 11, 2025
@martijnvg martijnvg requested a review from kkrik-es March 12, 2025 08:17
}

void bulkCollection() throws IOException {
// The leaf bucked collectors newer timestamp go first, other we capture the incorrect last value for counters and labels.
Copy link
Contributor

@kkrik-es kkrik-es Mar 12, 2025

Choose a reason for hiding this comment

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

The leaf bucket collectors with newer timestamp go first, to correctly capture the last value for counters and labels.

if (docValuesCount == 1) {
label.collect(docValues.nextValue());
} else {
var values = new Object[docValuesCount];
Copy link
Contributor

Choose a reason for hiding this comment

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

How large can this be? Do we need to use bigarrays to track its memory?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it's smaller than DOCID_BUFFER_SIZE.. Should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is for multivalued fields. If a document has a json array, then this is the size of the json array (actually the number of all unique values this document has for the field being read). Typically this is small.

Note that this has been this way also before this change. I don't recall issues around this.

firstTimeStampForBulkCollection = aggCtx.getTimestamp();
}
// buffer.add() always delegates to system.arraycopy() and checks buffer size for resizing purposes:
buffer.buffer[buffer.elementsCount++] = docId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: let's rename buffer to docIdBuffer, to avoid the buffer.buffer occurrence..

@kkrik-es kkrik-es requested a review from dnhatn March 12, 2025 13:08
Copy link
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

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

LGTM, added Nhat too to play it safe.

@martijnvg martijnvg merged commit ce3a778 into elastic:main Mar 13, 2025
17 checks passed
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 13, 2025
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
8.x
9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >enhancement :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data Team:StorageEngine v8.18.1 v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants