Skip to content

Introducing MergedSegmentWarmerFactory to support the extension of IndexWriter.IndexReaderWarmer #17881

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

Conversation

guojialiang92
Copy link
Contributor

@guojialiang92 guojialiang92 commented Apr 10, 2025

Description

In order to reduce the visibility delay of replicas in Segment Replication, we propose the idea of merged segment pre-copy in 17528. After discussion, we believe that it can produce good results in both local segment replication and remote store situations.

This PR is the beginning of supporting merged segments pre-copy. We introduce MergedSegmentWarmerFactory for Local/Remote merged segment pre copy.

Related Issues

Resolves #[17528]

Experiment

Test1: Replica Lag Time

We enable pre-copy in local on-disk segment replication to test the optimization effect.
We used two 16C64GB nodes, nyc_taxis workload, 2 primary shard and 1 replica shard for testing. The test command is as follows:

nohup opensearch-benchmark execute-test --target-hosts [10.204.62.132:9425](http://10.204.62.132:9425/)  --workload=nyc_taxis --pipeline=benchmark-only --workload-params='{"bulk_indexing_clients":10,"bulk_size":5000,"index_settings":{"index.number_of_shards":2,"index.number_of_replicas":1,"index.replication.type":"SEGMENT","index.routing.allocation.total_shards_per_node":2}}' --offline --results-format=csv --results-file=/home/result.csv --kill-running-processes > nohup.out 2>&1 &

We use command _cat/segment_replication to collect indicator current_lag every 5 seconds and compare the replica lag time when closing and opening pre-copy feature.

Result1: segment replication without pre-copy

segment replication without pre copy

Result2: segment replication with pre-copy

segment replication with pre copy

The X-axis represents logical time, collected every 5 seconds. The Y-axis represents the indicator current_lag collected through command _cat/segment_replication. We can see that the maximum lag time has been reduced from 66s to 2.9s, with more than 20 times optimization.

Test2: CPU util and P99 Read Latency

At the same time, we conducted a write-search test and focused on CPU util and P99 Read Latency. We can see that there is no significant change in query latency and CPU util.

Result1: segment replication without pre-copy

cpu util without pre copy

p99 read latency without pre copy

Result2: segment replication with pre-copy

cpu util with pre copy

p99 read latency with pre copy

The analysis of the reasons is as follows. CPU-intensive tasks are performed before pre-copy. There will be no significant CPU overhead due to the introduction of pre-copy. At the same time, the time cost of merging in phase SegmentMerger#merge should be much greater than the time spent in phase IndexReaderWarmer#warm. The additional synchronization time introduced by pre-copy should not account for a high proportion in the entire merge process.

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

❌ Gradle check result for e012362: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@ashking94
Copy link
Member

The replication lag improvement looks promising. There appears to be up to 5-6% higher CPU utilization with pre-copy. Is this reproducible each time, or can this be considered as general variability between multiple runs?

@guojialiang92
Copy link
Contributor Author

guojialiang92 commented Apr 11, 2025

Hi, @ashking94

The replication lag improvement looks promising.

Yeah, the improvementt is very obvious.

There appears to be up to 5-6% higher CPU utilization with pre-copy. Is this reproducible each time, or can this be considered as general variability between multiple runs?

Some explanation is needed here. Because the current value fluctuates, we generally care about the max and avg CPU utilization.

Taking node lf-byte-es-sr-dataplatform-two-data-0 as an example, we can see that when pre-copy is enabled, the maximum CPU utilization is reduced by 4.1% (from 67.3% to 63.2%), and the average CPU utilization is slightly higher by 0.6% (from 54.5% to 55.1%).

At the same time, we repeated the test of enabling pre-copy.

pre copy cpu util

It can be seen that the average CPU utilization of lf-byte-es-sr-dataplatform-two-data-0 has decreased by 2.7% (from 54.5% to 51.8%).

In summary, merged segments pre copy hardly introduces additional CPU overhead.

Signed-off-by: guojialiang <[email protected]>
@guojialiang92 guojialiang92 force-pushed the dev/support_merged_segment_warmer branch from 97fa12b to a6157f0 Compare April 14, 2025 15:46
Copy link
Member

@ashking94 ashking94 left a comment

Choose a reason for hiding this comment

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

LGTM, do address the unresolved comments if any.

Copy link
Contributor

✅ Gradle check result for a6157f0: SUCCESS

@guojialiang92
Copy link
Contributor Author

Thanks, @ashking94

LGTM, do address the unresolved comments if any.

All comments have been resolved, looking forward to merging the code.

@ashking94
Copy link
Member

@guojialiang92 can you resolve the conflicts?

…gment_warmer

# Conflicts:
#	CHANGELOG.md
#	server/src/main/java/org/opensearch/common/util/FeatureFlags.java
Copy link
Contributor

✅ Gradle check result for fa5481c: SUCCESS

@guojialiang92
Copy link
Contributor Author

@guojialiang92 can you resolve the conflicts?

@ashking94, It has been resolved.

@ashking94 ashking94 merged commit 80cb033 into opensearch-project:main Apr 15, 2025
31 checks passed
Harsh-87 pushed a commit to Harsh-87/OpenSearch that referenced this pull request May 7, 2025
…rWarmer (opensearch-project#17881)

* support merged segment warmer

Signed-off-by: guojialiang <[email protected]>

* Introduce MergedSegmentWarmerFactory for Local/Remote merged segment pre copy

Signed-off-by: guojialiang <[email protected]>

* add FeatureFlags.MERGED_SEGMENT_WARMER_EXPERIMENTAL_FLAG

Signed-off-by: guojialiang <[email protected]>

* add an entry in CHANGELOG

Signed-off-by: guojialiang <[email protected]>

* add validation

Signed-off-by: guojialiang <[email protected]>

* modify changelog entry

Signed-off-by: guojialiang <[email protected]>

* add comment

Signed-off-by: guojialiang <[email protected]>

* add comment

Signed-off-by: guojialiang <[email protected]>

---------

Signed-off-by: guojialiang <[email protected]>
Signed-off-by: Harsh Kothari <[email protected]>
Harsh-87 pushed a commit to Harsh-87/OpenSearch that referenced this pull request May 7, 2025
…rWarmer (opensearch-project#17881)

* support merged segment warmer

Signed-off-by: guojialiang <[email protected]>

* Introduce MergedSegmentWarmerFactory for Local/Remote merged segment pre copy

Signed-off-by: guojialiang <[email protected]>

* add FeatureFlags.MERGED_SEGMENT_WARMER_EXPERIMENTAL_FLAG

Signed-off-by: guojialiang <[email protected]>

* add an entry in CHANGELOG

Signed-off-by: guojialiang <[email protected]>

* add validation

Signed-off-by: guojialiang <[email protected]>

* modify changelog entry

Signed-off-by: guojialiang <[email protected]>

* add comment

Signed-off-by: guojialiang <[email protected]>

* add comment

Signed-off-by: guojialiang <[email protected]>

---------

Signed-off-by: guojialiang <[email protected]>
Signed-off-by: Harsh Kothari <[email protected]>
*
* @opensearch.internal
*/
public class LocalMergedSegmentWarmer implements IndexWriter.IndexReaderWarmer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would have preferred this in a follow-up PR :)

*/

/*
* Licensed to Elasticsearch under one or more contributor
Copy link
Member

Choose a reason for hiding this comment

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

I'm very late to this pr, but we need to remove the es part of these licenses.

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.

5 participants