Skip to content

Use a single array for buffering rate data points#140855

Merged
dnhatn merged 11 commits intoelastic:mainfrom
dnhatn:rate-single-array
Jan 20, 2026
Merged

Use a single array for buffering rate data points#140855
dnhatn merged 11 commits intoelastic:mainfrom
dnhatn:rate-single-array

Conversation

@dnhatn
Copy link
Member

@dnhatn dnhatn commented Jan 18, 2026

This change switches to a single array for buffering data points in rate aggregation, providing several benefits:

  1. Minimal memory waste: Previously, each group over-allocated 1/8 or an extra page of the required memory to minimize allocations. For example, with 10,000 time series and 30 time-buckets each, this could reserve an extra 10,000 * 30 * 16,384 = 4,915,200,000 bytes (~4.9GB), and with 8 concurrent drivers, up to 40GB of extra memory.

  2. Fewer objects, making it more GC-friendly.

  3. Easier future disk spill: With a single array, spilling the initial pages to disk is easier to implement.

This approach may result in more "slices" than before, since slices cannot be combined across segments. However, the slice merging process has been improved to reduce this overhead.

Performance tests with 100 hosts (270 million data points) show a 10% reduction in rate_1h response time (from 420ms to 380ms), though performance was not the primary goal of this change.

@dnhatn dnhatn force-pushed the rate-single-array branch 7 times, most recently from 371d577 to 0c5a312 Compare January 19, 2026 20:23
@dnhatn dnhatn force-pushed the rate-single-array branch from a1262fb to d49c6bd Compare January 19, 2026 22:32
@elastic elastic deleted a comment from elasticmachine Jan 19, 2026
@dnhatn
Copy link
Member Author

dnhatn commented Jan 19, 2026

Buildkite benchmark this with tsdb-metricsgen-240m-highcardinality please

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 19, 2026

💚 Build Succeeded

This build ran two tsdb-metricsgen-240m-highcardinality benchmarks to evaluate performance impact of this PR.

History

@dnhatn dnhatn changed the title WIP - single array for rate Jan 19, 2026
@dnhatn dnhatn added :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL >enhancement labels Jan 19, 2026
@elasticsearchmachine
Copy link
Collaborator

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

@dnhatn dnhatn requested review from JonasKunz and kkrik-es January 20, 2026 00:48
@dnhatn dnhatn marked this pull request as ready for review January 20, 2026 00:48
@elasticsearchmachine
Copy link
Collaborator

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

}

final void prepareSlicesOnly(int groupId, long firstTimestamp) {
if (valueCount > 0 && sliceGroupIds.get(sliceCount - 1) == groupId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naive question: is there an issue if sliceCount is 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, it gets incremented on the first value. Maybe an assert would help, just a nit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an assertion in f40616e

Copy link
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

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

LGTM, nice!

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.

Good job, Nhat. This should be faster, and it'll show up more once we reduce the other overheads.

dnhatn and others added 2 commits January 20, 2026 08:08
…pute/aggregation/AbstractRateGroupingFunction.java

Co-authored-by: Kostas Krikellas <131142368+kkrik-es@users.noreply.github.com>
…pute/aggregation/AbstractRateGroupingFunction.java

Co-authored-by: Jonas Kunz <j+github@kunzj.de>
@dnhatn
Copy link
Member Author

dnhatn commented Jan 20, 2026

@kkrik-es @JonasKunz Thanks for the review!

@dnhatn dnhatn merged commit 5c1521c into elastic:main Jan 20, 2026
35 checks passed
@dnhatn dnhatn deleted the rate-single-array branch January 20, 2026 18:48
@dnhatn
Copy link
Member Author

dnhatn commented Jan 20, 2026

@kkrik-es @JonasKunz I did another round of benchmarking. I think this change reduced the query time of rate_1h for 100 hosts by around 20% (from 440ms to 355ms), instead of the previously estimated 10%. I hope this improvement will be reflected in our competitive benchmark.

spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Jan 21, 2026
This change switches to a single array for buffering data points in rate 
aggregation, providing several benefits:

1. Minimal memory waste: Previously, each group over-allocated 1/8 or an
extra page of the required memory to minimize allocations. For example,
with 10,000 time series and 30 time-buckets each, this could reserve an
extra 10,000 * 30 * 16,384 = 4,915,200,000 bytes (~4.9GB), and with 8
concurrent drivers, up to 40GB of extra memory.

2. Fewer objects, making it more GC-friendly.

3. Easier future disk spill: With a single array, spilling the initial
pages to disk is easier to implement.

This approach may result in more "slices" than before, since slices 
cannot be combined across segments. However, the slice merging process
has been improved to reduce this overhead.

Performance tests with 100 hosts (270 million data points) show a 10% 
reduction in rate_1h response time (from 420ms to 380ms), though
performance was not the primary goal of this change.
@dnhatn dnhatn added the v9.3.1 label Jan 21, 2026
@dnhatn
Copy link
Member Author

dnhatn commented Jan 21, 2026

💚 All backports created successfully

Status Branch Result
9.3

Questions ?

Please refer to the Backport tool documentation

dnhatn added a commit to dnhatn/elasticsearch that referenced this pull request Jan 21, 2026
This change switches to a single array for buffering data points in rate
aggregation, providing several benefits:

1. Minimal memory waste: Previously, each group over-allocated 1/8 or an
extra page of the required memory to minimize allocations. For example,
with 10,000 time series and 30 time-buckets each, this could reserve an
extra 10,000 * 30 * 16,384 = 4,915,200,000 bytes (~4.9GB), and with 8
concurrent drivers, up to 40GB of extra memory.

2. Fewer objects, making it more GC-friendly.

3. Easier future disk spill: With a single array, spilling the initial
pages to disk is easier to implement.

This approach may result in more "slices" than before, since slices
cannot be combined across segments. However, the slice merging process
has been improved to reduce this overhead.

Performance tests with 100 hosts (270 million data points) show a 10%
reduction in rate_1h response time (from 420ms to 380ms), though
performance was not the primary goal of this change.

(cherry picked from commit 5c1521c)
dnhatn added a commit that referenced this pull request Jan 21, 2026
This change switches to a single array for buffering data points in rate
aggregation, providing several benefits:

1. Minimal memory waste: Previously, each group over-allocated 1/8 or an
extra page of the required memory to minimize allocations. For example,
with 10,000 time series and 30 time-buckets each, this could reserve an
extra 10,000 * 30 * 16,384 = 4,915,200,000 bytes (~4.9GB), and with 8
concurrent drivers, up to 40GB of extra memory.

2. Fewer objects, making it more GC-friendly.

3. Easier future disk spill: With a single array, spilling the initial
pages to disk is easier to implement.

This approach may result in more "slices" than before, since slices
cannot be combined across segments. However, the slice merging process
has been improved to reduce this overhead.

Performance tests with 100 hosts (270 million data points) show a 10%
reduction in rate_1h response time (from 420ms to 380ms), though
performance was not the primary goal of this change.

(cherry picked from commit 5c1521c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL Team:StorageEngine v9.3.1 v9.4.0

5 participants