-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Restricts snapshot concurrency based on available heap memory #136952
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
Open
joshua-adams-1
wants to merge
6
commits into
elastic:main
Choose a base branch
from
joshua-adams-1:blobstore-repo-concurrency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f9d2ba
Restricts snapshot concurrency based on available heap memory
joshua-adams-1 a5137b8
Update docs/changelog/136952.yaml
joshua-adams-1 4b9d4b0
Adds ByteSizeConstants
joshua-adams-1 84358c7
Merge branch 'blobstore-repo-concurrency' of https://github.com/joshu…
joshua-adams-1 8ac4fbc
Update setting to prevent index metadata reads from exceeding 10% of
joshua-adams-1 1b9884c
Merge branch 'main' into blobstore-repo-concurrency
joshua-adams-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 136952 | ||
| summary: Restricts snapshot concurrency based on available heap memory | ||
| area: Snapshot/Restore | ||
| type: bug | ||
| issues: | ||
| - 131822 |
16 changes: 16 additions & 0 deletions
16
server/src/main/java/org/elasticsearch/common/bytes/ByteSizeConstants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.common.bytes; | ||
|
|
||
| public class ByteSizeConstants { | ||
| public static int ONE_KILOBYTE_IN_BYTES = 1024; | ||
| public static int ONE_MEGABYTE_IN_BYTES = 1024 * ONE_KILOBYTE_IN_BYTES; | ||
| public static int ONE_GIGABYTE_IN_BYTES = 1024 * ONE_MEGABYTE_IN_BYTES; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| import org.elasticsearch.common.settings.ClusterSettings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.unit.ByteSizeUnit; | ||
| import org.elasticsearch.common.unit.ByteSizeValue; | ||
| import org.elasticsearch.common.util.MockBigArrays; | ||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
| import org.elasticsearch.core.TimeValue; | ||
|
|
@@ -90,6 +91,7 @@ | |
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.elasticsearch.common.bytes.ByteSizeConstants.ONE_GIGABYTE_IN_BYTES; | ||
| import static org.elasticsearch.repositories.RepositoryDataTests.generateRandomRepoData; | ||
| import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.INDEX_FILE_PREFIX; | ||
| import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.MAX_HEAP_SIZE_FOR_SNAPSHOT_DELETION_SETTING; | ||
|
|
@@ -113,6 +115,19 @@ public class BlobStoreRepositoryTests extends ESSingleNodeTestCase { | |
|
|
||
| static final String REPO_TYPE = "fs"; | ||
| private static final String TEST_REPO_NAME = "test-repo"; | ||
| /** | ||
| * The maximum number of threads possible to be used | ||
| */ | ||
| private static final int THREAD_POOL_MAX_SNAPSHOT_THREADS = 10; | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings() { | ||
| return Settings.builder() | ||
| .put(super.nodeSettings()) | ||
| // Mimic production | ||
| .put("thread_pool.snapshot.max", THREAD_POOL_MAX_SNAPSHOT_THREADS) | ||
| .build(); | ||
| } | ||
|
|
||
| public void testRetrieveSnapshots() { | ||
| final Client client = client(); | ||
|
|
@@ -859,4 +874,38 @@ public void testWriteToShardBlobToDelete() { | |
| .setPersistentSettings(Settings.builder().putNull(MAX_HEAP_SIZE_FOR_SNAPSHOT_DELETION_SETTING.getKey()).build()) | ||
| .get(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests whether we adjust the maximum concurrency when deleting snapshots | ||
| * according to the size of the heap memory | ||
| */ | ||
| public void testMaxIndexDeletionConcurrency() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is different to the previous. This is just a basic unit test to ensure that the function of heap memory -> snapshot threads is as expected, but doesn't test whether all threads are properly utilised |
||
| // Randomly generate a heap size up to 10GB. | ||
| long heapSizeInBytes = randomLongBetween(0, 10L * ONE_GIGABYTE_IN_BYTES); | ||
| // We expect at most only 10% of the total heap space to be used when loading index metadata | ||
| long heapAvailableForIndexMetaData = heapSizeInBytes / 10; | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT) | ||
| .setPersistentSettings( | ||
| Settings.builder() | ||
| .put("repositories.blobstore.max_heap_size_for_index_metadata", heapAvailableForIndexMetaData + "b") | ||
| .build() | ||
| ) | ||
| .get(); | ||
|
|
||
| final var repo = setupRepo(); | ||
|
|
||
| // We use 50MB as a heuristic of how many index metadata objects we could load concurrently | ||
| long maxConcurrentThreads = Math.max(1, ByteSizeValue.of(heapAvailableForIndexMetaData, ByteSizeUnit.BYTES).getMb() / 50); | ||
|
|
||
| assertEquals(Math.min(maxConcurrentThreads, THREAD_POOL_MAX_SNAPSHOT_THREADS), repo.getMaxIndexDeletionConcurrency()); | ||
|
|
||
| // reset original default setting | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT) | ||
| .setPersistentSettings(Settings.builder().putNull("repositories.blobstore.max_heap_size_for_index_metadata").build()) | ||
| .get(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am extending this test to ensure that, depending on the available heap memory, we throttle the number of concurrent snapshot threads accordingly