Search in sources :

Example 6 with IndexingPressureStats

use of org.opensearch.index.stats.IndexingPressureStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaThroughputDegradationParam.

public void testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaThroughputDegradationParam() throws InterruptedException {
    Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "10KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), false).put(ShardIndexingPressureMemoryManager.THROUGHPUT_DEGRADATION_LIMITS.getKey(), 1).put(ShardIndexingPressureSettings.REQUEST_SIZE_WINDOW.getKey(), 1).build();
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    boolean randomBoolean = randomBoolean();
    try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 1 * 1024, false);
        Releasable coordinating1 = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 3 * 1024, false);
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 1 * 1024, false);
        Releasable primary1 = shardIndexingPressure.markPrimaryOperationStarted(shardId, 3 * 1024, false)) {
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryBytes());
        assertEquals(8 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals((long) (8 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
        // Adding delay in the current in flight request to mimic throughput degradation
        Thread.sleep(100);
    }
    if (randomBoolean) {
        Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 8 * 1024, false);
        coordinating.close();
    } else {
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 8 * 1024, false);
        primary.close();
    }
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    if (randomBoolean) {
        assertEquals(0, shardStats.getCoordinatingRejections());
        assertEquals(1, shardStats.getCoordinatingThroughputDegradationLimitsBreachedRejections());
        assertEquals(0, shardStats.getCurrentCoordinatingBytes());
        assertEquals(12 * 1024, shardStats.getTotalCoordinatingBytes());
    } else {
        assertEquals(0, shardStats.getPrimaryRejections());
        assertEquals(1, shardStats.getPrimaryThroughputDegradationLimitsBreachedRejections());
        assertEquals(0, shardStats.getCurrentPrimaryBytes());
        assertEquals(12 * 1024, shardStats.getTotalPrimaryBytes());
    }
    assertEquals(10, shardStats.getCurrentPrimaryAndCoordinatingLimits());
    assertEquals(0, shardStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(16 * 1024, shardStats.getTotalCombinedCoordinatingAndPrimaryBytes());
    IndexingPressureStats nodeStats = shardIndexingPressure.stats();
    if (randomBoolean) {
        assertEquals(0, nodeStats.getCoordinatingRejections());
        assertEquals(0, nodeStats.getCurrentCoordinatingBytes());
    } else {
        assertEquals(0, nodeStats.getPrimaryRejections());
        assertEquals(0, nodeStats.getCurrentPrimaryBytes());
    }
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 7 with IndexingPressureStats

use of org.opensearch.index.stats.IndexingPressureStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testReplicaShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam.

public void testReplicaShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam() throws InterruptedException {
    Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "10KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 1).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), false).build();
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    try (Releasable replica = shardIndexingPressure.markReplicaOperationStarted(shardId, 1 * 1024, false)) {
        assertEquals(1 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentReplicaBytes());
        assertEquals((long) (1 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentReplicaLimits());
    }
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getCurrentReplicaBytes());
    assertEquals(1 * 1024, shardStats.getTotalReplicaBytes());
    assertEquals(15, shardStats.getCurrentReplicaLimits());
    Thread.sleep(25);
    // Total Bytes are 14*1024 and node limit is 15*1024
    try (Releasable replica = shardIndexingPressure.markReplicaOperationStarted(shardId, 10 * 1024, false);
        Releasable replica1 = shardIndexingPressure.markReplicaOperationStarted(shardId, 2 * 1024, false)) {
        Releasable replica2 = shardIndexingPressure.markReplicaOperationStarted(shardId, 2 * 1024, false);
        replica2.close();
    }
    shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getReplicaRejections());
    assertEquals(0, shardStats.getCurrentReplicaBytes());
    assertEquals(1, shardStats.getReplicaLastSuccessfulRequestLimitsBreachedRejections());
    IndexingPressureStats nodeStats = shardIndexingPressure.stats();
    assertEquals(0, nodeStats.getReplicaRejections());
    assertEquals(0, nodeStats.getCurrentReplicaBytes());
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 8 with IndexingPressureStats

use of org.opensearch.index.stats.IndexingPressureStats in project OpenSearch by opensearch-project.

the class IndexingPressureTests method testReplicaRejections.

public void testReplicaRejections() {
    IndexingPressure indexingPressure = new IndexingPressure(settings);
    try (Releasable coordinating = indexingPressure.markCoordinatingOperationStarted(1024 * 3, false);
        Releasable primary = indexingPressure.markPrimaryOperationStarted(1024 * 3, false);
        Releasable replica = indexingPressure.markReplicaOperationStarted(1024 * 3, false)) {
        // Replica will not be rejected until replica bytes > 15KB
        Releasable replica2 = indexingPressure.markReplicaOperationStarted(1024 * 11, false);
        assertEquals(1024 * 14, indexingPressure.stats().getCurrentReplicaBytes());
        // Replica will be rejected once we cross 15KB
        expectThrows(OpenSearchRejectedExecutionException.class, () -> indexingPressure.markReplicaOperationStarted(1024 * 2, false));
        IndexingPressureStats stats = indexingPressure.stats();
        assertEquals(1, stats.getReplicaRejections());
        assertEquals(1024 * 14, stats.getCurrentReplicaBytes());
        // Replica can be forced
        Releasable forced = indexingPressure.markPrimaryOperationStarted(1024 * 2, true);
        assertEquals(1, indexingPressure.stats().getReplicaRejections());
        assertEquals(1024 * 14, indexingPressure.stats().getCurrentReplicaBytes());
        forced.close();
        replica2.close();
    }
    assertEquals(1024 * 14, indexingPressure.stats().getTotalReplicaBytes());
}
Also used : Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats)

Example 9 with IndexingPressureStats

use of org.opensearch.index.stats.IndexingPressureStats in project OpenSearch by opensearch-project.

the class IndexingPressureTests method testMemoryBytesMarkedAndReleased.

public void testMemoryBytesMarkedAndReleased() {
    IndexingPressure indexingPressure = new IndexingPressure(settings);
    try (Releasable coordinating = indexingPressure.markCoordinatingOperationStarted(10, false);
        Releasable coordinating2 = indexingPressure.markCoordinatingOperationStarted(50, false);
        Releasable primary = indexingPressure.markPrimaryOperationStarted(15, true);
        Releasable primary2 = indexingPressure.markPrimaryOperationStarted(5, false);
        Releasable replica = indexingPressure.markReplicaOperationStarted(25, true);
        Releasable replica2 = indexingPressure.markReplicaOperationStarted(10, false)) {
        IndexingPressureStats stats = indexingPressure.stats();
        assertEquals(60, stats.getCurrentCoordinatingBytes());
        assertEquals(20, stats.getCurrentPrimaryBytes());
        assertEquals(80, stats.getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals(35, stats.getCurrentReplicaBytes());
    }
    IndexingPressureStats stats = indexingPressure.stats();
    assertEquals(0, stats.getCurrentCoordinatingBytes());
    assertEquals(0, stats.getCurrentPrimaryBytes());
    assertEquals(0, stats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(0, stats.getCurrentReplicaBytes());
    assertEquals(60, stats.getTotalCoordinatingBytes());
    assertEquals(20, stats.getTotalPrimaryBytes());
    assertEquals(80, stats.getTotalCombinedCoordinatingAndPrimaryBytes());
    assertEquals(35, stats.getTotalReplicaBytes());
}
Also used : Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats)

Example 10 with IndexingPressureStats

use of org.opensearch.index.stats.IndexingPressureStats in project OpenSearch by opensearch-project.

the class IndexingPressureTests method testAvoidDoubleAccounting.

public void testAvoidDoubleAccounting() {
    IndexingPressure indexingPressure = new IndexingPressure(settings);
    try (Releasable coordinating = indexingPressure.markCoordinatingOperationStarted(10, false);
        Releasable primary = indexingPressure.markPrimaryOperationLocalToCoordinatingNodeStarted(15)) {
        IndexingPressureStats stats = indexingPressure.stats();
        assertEquals(10, stats.getCurrentCoordinatingBytes());
        assertEquals(15, stats.getCurrentPrimaryBytes());
        assertEquals(10, stats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    }
    IndexingPressureStats stats = indexingPressure.stats();
    assertEquals(0, stats.getCurrentCoordinatingBytes());
    assertEquals(0, stats.getCurrentPrimaryBytes());
    assertEquals(0, stats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(10, stats.getTotalCoordinatingBytes());
    assertEquals(15, stats.getTotalPrimaryBytes());
    assertEquals(10, stats.getTotalCombinedCoordinatingAndPrimaryBytes());
}
Also used : Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats)

Aggregations

Releasable (org.opensearch.common.lease.Releasable)22 IndexingPressureStats (org.opensearch.index.stats.IndexingPressureStats)22 ShardId (org.opensearch.index.shard.ShardId)18 IndexingPressurePerShardStats (org.opensearch.index.stats.IndexingPressurePerShardStats)18 ClusterSettings (org.opensearch.common.settings.ClusterSettings)12 Settings (org.opensearch.common.settings.Settings)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)2 ShardIndexingPressureStats (org.opensearch.index.stats.ShardIndexingPressureStats)2 BulkRequest (org.opensearch.action.bulk.BulkRequest)1