-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[Profiling] Query in parallel only if beneficial #103061
Merged
danielmitterdorfer
merged 3 commits into
elastic:main
from
danielmitterdorfer:adaptive-slicing
Dec 7, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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,5 @@ | ||
pr: 103061 | ||
summary: "[Profiling] Query in parallel only if beneficial" | ||
area: Application | ||
type: bug | ||
issues: [] |
60 changes: 60 additions & 0 deletions
60
x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/IndexAllocation.java
This file contains 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,60 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.profiling; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.cluster.routing.allocation.DataTier; | ||
import org.elasticsearch.index.Index; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
final class IndexAllocation { | ||
private IndexAllocation() { | ||
// no instances intended | ||
} | ||
|
||
static boolean isAnyAssignedToNode(ClusterState state, List<Index> indices, Predicate<DiscoveryNode> nodePredicate) { | ||
for (Index index : indices) { | ||
IndexMetadata metadata = state.getMetadata().index(index); | ||
if (metadata == null) { | ||
continue; | ||
} | ||
IndexRoutingTable routingTable = state.routingTable().index(index); | ||
if (routingTable == null) { | ||
continue; | ||
} | ||
for (ShardRouting shardRouting : routingTable.randomAllActiveShardsIt()) { | ||
if (shardRouting.assignedToNode() == false) { | ||
continue; | ||
} | ||
DiscoveryNode assignedNode = state.nodes().get(shardRouting.currentNodeId()); | ||
if (nodePredicate.test(assignedNode)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Determines whether any of the provided indices is allocated to the warm or cold tier. Machines on these | ||
* tiers usually use spinning disks. | ||
* | ||
* @param state Current cluster state. | ||
* @param indices A list of indices to check. | ||
* @return <code>true</code> iff at least one index is allocated to either a warm or cold data node. | ||
*/ | ||
static boolean isAnyOnWarmOrColdTier(ClusterState state, List<Index> indices) { | ||
return isAnyAssignedToNode(state, indices, n -> DataTier.isWarmNode(n) || DataTier.isColdNode(n)); | ||
} | ||
} |
This file contains 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
122 changes: 122 additions & 0 deletions
122
...lugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/IndexAllocationTests.java
This file contains 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,122 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.profiling; | ||
|
||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlocks; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodeRole; | ||
import org.elasticsearch.cluster.node.DiscoveryNodeUtils; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable; | ||
import org.elasticsearch.cluster.routing.RecoverySource; | ||
import org.elasticsearch.cluster.routing.RoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.cluster.routing.UnassignedInfo; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexVersion; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class IndexAllocationTests extends ESTestCase { | ||
private final Index hot = idx("hot"); | ||
private final Index warm = idx("warm"); | ||
private final Index cold = idx("cold"); | ||
private final Index frozen = idx("frozen"); | ||
|
||
public void testEmptyIndicesNotOnWarmColdTier() { | ||
assertFalse(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), Collections.emptyList())); | ||
} | ||
|
||
public void testOtherIndicesNotOnWarmColdTier() { | ||
assertFalse(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), List.of(hot, frozen))); | ||
} | ||
|
||
public void testIndicesOnWarmColdTier() { | ||
assertTrue(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), List.of(warm))); | ||
assertTrue(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), List.of(cold))); | ||
} | ||
|
||
public void testMixedIndicesOnWarmColdTier() { | ||
assertTrue(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), List.of(hot, warm))); | ||
assertTrue(IndexAllocation.isAnyOnWarmOrColdTier(clusterState(), List.of(frozen, cold))); | ||
} | ||
|
||
/** | ||
* Creates a cluster state that represents several indices: | ||
* | ||
* <ul> | ||
* <li><code>hot</code> assigned to a hot-tier node named <code>n-hot</code></li> | ||
* <li><code>warm</code> assigned to a warm-tier node named <code>n-warm</code></li> | ||
* <li><code>cold</code> assigned to a cold-tier node named <code>n-cold</code></li> | ||
* <li><code>frozen</code> assigned to a frozen-tier node named <code>n-frozen</code></li> | ||
* </ul> | ||
*/ | ||
private ClusterState clusterState() { | ||
DiscoveryNode node = DiscoveryNodeUtils.create("node"); | ||
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node); | ||
|
||
nodesBuilder.add(DiscoveryNodeUtils.builder("n-" + hot.getName()).roles(Set.of(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)).build()); | ||
nodesBuilder.add(DiscoveryNodeUtils.builder("n-" + warm.getName()).roles(Set.of(DiscoveryNodeRole.DATA_WARM_NODE_ROLE)).build()); | ||
nodesBuilder.add(DiscoveryNodeUtils.builder("n-" + cold.getName()).roles(Set.of(DiscoveryNodeRole.DATA_COLD_NODE_ROLE)).build()); | ||
nodesBuilder.add( | ||
DiscoveryNodeUtils.builder("n-" + frozen.getName()).roles(Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE)).build() | ||
); | ||
|
||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); | ||
Map<String, IndexMetadata> indices = new HashMap<>(); | ||
for (Index index : List.of(hot, warm, cold, frozen)) { | ||
indices.put(index.getName(), metadata(index)); | ||
ShardRouting shardRouting = ShardRouting.newUnassigned( | ||
new ShardId(index, 0), | ||
true, | ||
RecoverySource.ExistingStoreRecoverySource.INSTANCE, | ||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), | ||
ShardRouting.Role.DEFAULT | ||
); | ||
|
||
shardRouting = shardRouting.initialize("n-" + index.getName(), null, 0).moveToStarted(0); | ||
routingTableBuilder.add( | ||
IndexRoutingTable.builder(index) | ||
.addIndexShard(IndexShardRoutingTable.builder(shardRouting.shardId()).addShard(shardRouting)) | ||
); | ||
} | ||
|
||
return ClusterState.builder(new ClusterName("test")) | ||
.metadata(Metadata.builder().indices(indices).build()) | ||
.blocks(new ClusterBlocks.Builder().build()) | ||
.nodes(nodesBuilder) | ||
.routingTable(routingTableBuilder) | ||
.build(); | ||
} | ||
|
||
private IndexMetadata metadata(Index index) { | ||
final Settings settings = Settings.builder() | ||
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) | ||
.put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID()) | ||
.build(); | ||
return IndexMetadata.builder(index.getName()).settings(settings).numberOfShards(1).numberOfReplicas(0).build(); | ||
} | ||
|
||
private Index idx(String name) { | ||
return new Index(name, UUID.randomUUID().toString()); | ||
} | ||
|
||
} |
This file contains 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.
Just a question. Did you test with 2 slices on the warm tier as well? If yes, what was the ~ impact?
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 just dug through my notes. I believe I did such a test but the superior alternative in all cases was just using a single slice (apparently I did not even bother to write down the results for anything except the default value of
16
and a single slice...).