use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class ShardIndexingPressureConcurrentExecutionTests method testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections.
public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() throws Exception {
final int NUM_THREADS = 100;
final Thread[] threads = new Thread[NUM_THREADS];
final Releasable[] releasables = new Releasable[NUM_THREADS];
AtomicInteger rejectionCount = new AtomicInteger();
ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
Index index = new Index("IndexName", "UUID");
ShardId shardId1 = new ShardId(index, 0);
boolean randomBoolean = randomBoolean();
for (int i = 0; i < NUM_THREADS; i++) {
int counter = i;
threads[i] = new Thread(() -> {
try {
if (randomBoolean) {
releasables[counter] = shardIndexingPressure.markCoordinatingOperationStarted(shardId1, 200, false);
} else {
releasables[counter] = shardIndexingPressure.markPrimaryOperationStarted(shardId1, 200, false);
}
} catch (OpenSearchRejectedExecutionException e) {
rejectionCount.addAndGet(1);
}
});
threads[i].start();
}
for (Thread t : threads) {
t.join();
}
IndexingPressureStats nodeStats = shardIndexingPressure.stats();
ShardIndexingPressureStats shardStats = shardIndexingPressure.shardStats();
if (randomBoolean) {
assertEquals(rejectionCount.get(), nodeStats.getCoordinatingRejections());
assertTrue(shardStats.getIndexingPressureShardStats(shardId1).getCurrentCoordinatingBytes() < 50 * 200);
} else {
assertTrue(shardStats.getIndexingPressureShardStats(shardId1).getCurrentPrimaryBytes() < 50 * 200);
assertEquals(rejectionCount.get(), nodeStats.getPrimaryRejections());
}
assertTrue(nodeStats.getCurrentCombinedCoordinatingAndPrimaryBytes() < 50 * 200);
assertTrue(shardStats.getIndexingPressureShardStats(shardId1).getCurrentCombinedCoordinatingAndPrimaryBytes() < 50 * 200);
for (Releasable releasable : releasables) {
if (releasable != null) {
releasable.close();
}
}
nodeStats = shardIndexingPressure.stats();
IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1);
assertNull(shardStoreStats);
shardStats = shardIndexingPressure.coldStats();
if (randomBoolean) {
assertEquals(rejectionCount.get(), nodeStats.getCoordinatingRejections());
assertEquals(rejectionCount.get(), shardStats.getIndexingPressureShardStats(shardId1).getCoordinatingNodeLimitsBreachedRejections());
assertEquals(0, shardStats.getIndexingPressureShardStats(shardId1).getCurrentCoordinatingBytes());
} else {
assertEquals(rejectionCount.get(), nodeStats.getPrimaryRejections());
assertEquals(rejectionCount.get(), shardStats.getIndexingPressureShardStats(shardId1).getPrimaryNodeLimitsBreachedRejections());
assertEquals(0, shardStats.getIndexingPressureShardStats(shardId1).getCurrentPrimaryBytes());
}
assertEquals(0, nodeStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
assertEquals(0, shardStats.getIndexingPressureShardStats(shardId1).getCurrentCombinedCoordinatingAndPrimaryBytes());
assertEquals(10, shardStats.getIndexingPressureShardStats(shardId1).getCurrentPrimaryAndCoordinatingLimits());
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class ShardIndexingPressureConcurrentExecutionTests method testCoordinatingPrimaryThreadedLastSuccessfulRequestsAndRejection.
public void testCoordinatingPrimaryThreadedLastSuccessfulRequestsAndRejection() throws Exception {
Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "250KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), true).put(ShardIndexingPressureMemoryManager.THROUGHPUT_DEGRADATION_LIMITS.getKey(), 1).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 100).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").build();
final int NUM_THREADS = scaledRandomIntBetween(110, 150);
ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
Index index = new Index("IndexName", "UUID");
ShardId shardId1 = new ShardId(index, 0);
boolean randomBoolean = randomBoolean();
// One request being successful
if (randomBoolean) {
Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId1, 10, false);
coordinating.close();
} else {
Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId1, 10, false);
primary.close();
}
// Generating a load such that requests are blocked requests.
Releasable[] releasables;
if (randomBoolean) {
releasables = fireConcurrentRequests(NUM_THREADS, shardIndexingPressure, shardId1, 10, OperationType.COORDINATING);
} else {
releasables = fireConcurrentRequests(NUM_THREADS, shardIndexingPressure, shardId1, 10, OperationType.PRIMARY);
}
// Mimic the time elapsed after requests being stuck
Thread.sleep(randomIntBetween(50, 100));
// Generate a load which breaches both primary parameter
if (randomBoolean) {
expectThrows(OpenSearchRejectedExecutionException.class, () -> shardIndexingPressure.markCoordinatingOperationStarted(shardId1, 200 * 1024, false));
} else {
expectThrows(OpenSearchRejectedExecutionException.class, () -> shardIndexingPressure.markPrimaryOperationStarted(shardId1, 200 * 1024, false));
}
for (int i = 0; i < NUM_THREADS; i++) {
releasables[i].close();
}
if (randomBoolean) {
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentCoordinatingBytes());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingThroughputDegradationLimitsBreachedRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingNodeLimitsBreachedRejections());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingLastSuccessfulRequestLimitsBreachedRejections());
} else {
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentPrimaryBytes());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryThroughputDegradationLimitsBreachedRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryNodeLimitsBreachedRejections());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryLastSuccessfulRequestLimitsBreachedRejections());
}
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentCombinedCoordinatingAndPrimaryBytes());
assertEquals(256, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentPrimaryAndCoordinatingLimits());
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class ShardIndexingPressureConcurrentExecutionTests method testCoordinatingPrimaryThreadedNodeLimitsAndRejection.
public void testCoordinatingPrimaryThreadedNodeLimitsAndRejection() throws Exception {
Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "250KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), true).put(ShardIndexingPressureMemoryManager.THROUGHPUT_DEGRADATION_LIMITS.getKey(), 1).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 100).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").build();
final int NUM_THREADS = scaledRandomIntBetween(100, 150);
ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
Index index = new Index("IndexName", "UUID");
ShardId shardId1 = new ShardId(index, 0);
boolean randomBoolean = randomBoolean();
// Generating a load to such that the requests in the window shows degradation in throughput.
Releasable[] releasables;
if (randomBoolean) {
releasables = fireConcurrentRequestsWithUniformDelay(NUM_THREADS, shardIndexingPressure, shardId1, 10, randomIntBetween(50, 100), OperationType.COORDINATING);
} else {
releasables = fireConcurrentRequestsWithUniformDelay(NUM_THREADS, shardIndexingPressure, shardId1, 10, randomIntBetween(50, 100), OperationType.PRIMARY);
}
// Generate a load which breaches both primary parameter
if (randomBoolean) {
expectThrows(OpenSearchRejectedExecutionException.class, () -> shardIndexingPressure.markCoordinatingOperationStarted(shardId1, 240 * 1024, false));
} else {
expectThrows(OpenSearchRejectedExecutionException.class, () -> shardIndexingPressure.markPrimaryOperationStarted(shardId1, 240 * 1024, false));
}
for (int i = 0; i < NUM_THREADS; i++) {
releasables[i].close();
}
if (randomBoolean) {
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentCoordinatingBytes());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingThroughputDegradationLimitsBreachedRejections());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingNodeLimitsBreachedRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCoordinatingLastSuccessfulRequestLimitsBreachedRejections());
} else {
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentPrimaryBytes());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryThroughputDegradationLimitsBreachedRejections());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryNodeLimitsBreachedRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getPrimaryLastSuccessfulRequestLimitsBreachedRejections());
}
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentCombinedCoordinatingAndPrimaryBytes());
assertEquals(256, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentPrimaryAndCoordinatingLimits());
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class ShardIndexingPressureConcurrentExecutionTests method testReplicaConcurrentUpdatesOnShardIndexingPressureTrackerObjects.
public void testReplicaConcurrentUpdatesOnShardIndexingPressureTrackerObjects() throws Exception {
final int NUM_THREADS = scaledRandomIntBetween(100, 400);
ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
Index index = new Index("IndexName", "new_uuid");
ShardId shardId1 = new ShardId(index, 0);
final Releasable[] releasables = fireConcurrentRequests(NUM_THREADS, shardIndexingPressure, shardId1, 20, OperationType.REPLICA);
IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1);
assertThat(shardStoreStats.getCurrentReplicaLimits(), Matchers.greaterThan(100L));
CommonStatsFlags statsFlag = new CommonStatsFlags();
statsFlag.includeAllShardIndexingPressureTrackers(true);
IndexingPressurePerShardStats shardStoreStats2 = shardIndexingPressure.shardStats(statsFlag).getIndexingPressureShardStats(shardId1);
;
assertEquals(shardStoreStats.getCurrentReplicaLimits(), shardStoreStats2.getCurrentReplicaLimits());
statsFlag.includeOnlyTopIndexingPressureMetrics(true);
assertNull(shardIndexingPressure.shardStats(statsFlag).getIndexingPressureShardStats(shardId1));
statsFlag.includeOnlyTopIndexingPressureMetrics(false);
for (int i = 0; i < NUM_THREADS; i++) {
releasables[i].close();
}
// No object in host store as no active shards
shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1);
assertNull(shardStoreStats);
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentReplicaBytes());
assertEquals(15, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentReplicaLimits());
shardStoreStats2 = shardIndexingPressure.shardStats(statsFlag).getIndexingPressureShardStats(shardId1);
;
assertEquals(shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentReplicaLimits(), shardStoreStats2.getCurrentReplicaLimits());
statsFlag.includeAllShardIndexingPressureTrackers(false);
assertNull(shardIndexingPressure.shardStats(statsFlag).getIndexingPressureShardStats(shardId1));
}
use of org.opensearch.common.lease.Releasable in project OpenSearch by opensearch-project.
the class ShardIndexingPressureConcurrentExecutionTests method testReplicaThreadedNodeLimitsAndRejection.
public void testReplicaThreadedNodeLimitsAndRejection() throws Exception {
Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "250KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), true).put(ShardIndexingPressureMemoryManager.THROUGHPUT_DEGRADATION_LIMITS.getKey(), 1).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 100).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").build();
final int NUM_THREADS = scaledRandomIntBetween(100, 150);
ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
Index index = new Index("IndexName", "UUID");
ShardId shardId1 = new ShardId(index, 0);
// Generating a load to such that the requests in the window shows degradation in throughput.
final Releasable[] releasables = fireConcurrentRequestsWithUniformDelay(NUM_THREADS, shardIndexingPressure, shardId1, 10, randomIntBetween(50, 100), OperationType.COORDINATING);
// Generate a load which breaches both primary parameter
expectThrows(OpenSearchRejectedExecutionException.class, () -> shardIndexingPressure.markReplicaOperationStarted(shardId1, 340 * 1024, false));
for (int i = 0; i < NUM_THREADS; i++) {
releasables[i].close();
}
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentReplicaBytes());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getReplicaRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getReplicaThroughputDegradationLimitsBreachedRejections());
assertEquals(1, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getReplicaNodeLimitsBreachedRejections());
assertEquals(0, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getReplicaLastSuccessfulRequestLimitsBreachedRejections());
assertEquals(384, shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId1).getCurrentReplicaLimits());
}
Aggregations