forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profiling] Query in parallel only if beneficial (elastic#103061)
With this commit we check index allocation before we do key-value lookups. To reduce latency, key-value lookups are done in parallel for multiple slices of data. However, on nodes with spinning disks, parallel accesses are harmful. Therefore, we check whether any index is allocated either to the warm or cold tier (which are usually on spinning disks) and disable parallel key-value lookups. This has improved latency on the warm tier by about 10% in our experiments.
- Loading branch information
1 parent
80efdd1
commit eea5f6e
Showing
5 changed files
with
211 additions
and
5 deletions.
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