Search in sources :

Example 6 with StoreTimer

use of com.apple.foundationdb.record.provider.common.StoreTimer in project fdb-record-layer by FoundationDB.

the class FDBStoreTimerTest method counterDifferenceTest.

@Test
public void counterDifferenceTest() {
    RecordCursor<KeyValue> kvc = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setScanProperties(ScanProperties.FORWARD_SCAN).setRange(TupleRange.ALL).build();
    // see the timer counts from some onNext calls
    FDBStoreTimer latestTimer = context.getTimer();
    StoreTimerSnapshot savedTimer;
    StoreTimer diffTimer;
    // get a snapshot from latestTimer before advancing cursor
    savedTimer = StoreTimerSnapshot.from(latestTimer);
    // advance the cursor once
    kvc.onNext().join();
    // the diff from latestTimer minus savedTimer will have the timer cost from the single cursor advance
    diffTimer = StoreTimer.getDifference(latestTimer, savedTimer);
    Map<String, Number> diffKVs;
    diffKVs = diffTimer.getKeysAndValues();
    assertThat(diffKVs, hasKey("load_scan_entry_count"));
    assertEquals(1, diffKVs.get("load_scan_entry_count").intValue());
    assertThat(diffKVs, hasKey("load_key_value_count"));
    assertEquals(1, diffKVs.get("load_key_value_count").intValue());
    // get a snapshot from latestTimer after the single cursor advance
    savedTimer = StoreTimerSnapshot.from(latestTimer);
    // advance the cursor more times
    final int numAdvances = 5;
    for (int i = 0; i < numAdvances; i++) {
        kvc.onNext().join();
    }
    // the diff from latestTimer and savedTimer will have the timer cost from the subsequent cursor advances
    diffTimer = StoreTimer.getDifference(latestTimer, savedTimer);
    diffKVs = diffTimer.getKeysAndValues();
    assertThat(diffKVs, hasKey("load_scan_entry_count"));
    assertEquals(numAdvances, diffKVs.get("load_scan_entry_count").intValue());
    assertThat(diffKVs, hasKey("load_key_value_count"));
    assertEquals(numAdvances, diffKVs.get("load_key_value_count").intValue(), numAdvances);
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) KeyValue(com.apple.foundationdb.KeyValue) StoreTimerSnapshot(com.apple.foundationdb.record.provider.common.StoreTimerSnapshot) Test(org.junit.jupiter.api.Test)

Example 7 with StoreTimer

use of com.apple.foundationdb.record.provider.common.StoreTimer in project fdb-record-layer by FoundationDB.

the class FDBStoreTimerTest method timeoutCounterDifferenceTest.

@Test
public void timeoutCounterDifferenceTest() {
    RecordCursor<KeyValue> kvc = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setScanProperties(ScanProperties.FORWARD_SCAN).setRange(TupleRange.ALL).build();
    FDBStoreTimer latestTimer = context.getTimer();
    CompletableFuture<RecordCursorResult<KeyValue>> fkvr;
    RecordCursorResult<KeyValue> kvr;
    // record timeout
    latestTimer.recordTimeout(FDBStoreTimer.Waits.WAIT_ADVANCE_CURSOR, System.nanoTime() - 5000);
    // the latest timer should have recorded the one timeout event
    Map<String, Number> diffKVs;
    diffKVs = latestTimer.getKeysAndValues();
    assertEquals(1, diffKVs.get("wait_advance_cursor_timeout_count").intValue());
    assertTrue(diffKVs.get("wait_advance_cursor_timeout_micros").intValue() > 0);
    assertThat(diffKVs.get("wait_advance_cursor_timeout_micros").intValue(), greaterThan(0));
    // advance the cursor without timing out
    latestTimer.record(FDBStoreTimer.Waits.WAIT_ADVANCE_CURSOR, System.nanoTime());
    latestTimer.record(FDBStoreTimer.Waits.WAIT_ADVANCE_CURSOR, System.nanoTime());
    // record the state after the first timeout event and generate some more timeout events
    StoreTimerSnapshot savedTimer;
    savedTimer = StoreTimerSnapshot.from(latestTimer);
    final int numTimeouts = 3;
    for (int i = 0; i < numTimeouts; i++) {
        latestTimer.recordTimeout(FDBStoreTimer.Waits.WAIT_ADVANCE_CURSOR, System.nanoTime() - 5000);
    }
    // should have the additional timeout events in latestTimer
    diffKVs = latestTimer.getKeysAndValues();
    assertEquals(numTimeouts + 1, diffKVs.get("wait_advance_cursor_timeout_count").intValue());
    assertThat(diffKVs.get("wait_advance_cursor_timeout_micros").intValue(), greaterThan(0));
    // the savedTimer should only have recorded the first timeout event and hence the difference is the numTimeout events that occurred after that
    StoreTimer diffTimer;
    diffTimer = StoreTimer.getDifference(latestTimer, savedTimer);
    diffKVs = diffTimer.getKeysAndValues();
    assertEquals(numTimeouts, diffKVs.get("wait_advance_cursor_timeout_count").intValue());
    assertThat(diffKVs.get("wait_advance_cursor_timeout_micros").intValue(), greaterThan(0));
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) KeyValue(com.apple.foundationdb.KeyValue) StoreTimerSnapshot(com.apple.foundationdb.record.provider.common.StoreTimerSnapshot) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Test(org.junit.jupiter.api.Test)

Example 8 with StoreTimer

use of com.apple.foundationdb.record.provider.common.StoreTimer in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method indexPlan.

@Test
public void indexPlan() {
    final String indexName = "an_index";
    StoreTimer timer = new FDBStoreTimer();
    RecordQueryPlan plan = indexPlanEquals(indexName, VALUE);
    plan.logPlanStructure(timer);
    assertUsesIndexes(plan, Lists.newArrayList(indexName));
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_INDEX), 1);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Test(org.junit.jupiter.api.Test)

Example 9 with StoreTimer

use of com.apple.foundationdb.record.provider.common.StoreTimer in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method fullScan.

@Test
public void fullScan() {
    StoreTimer timer = new FDBStoreTimer();
    RecordQueryPlan plan = new RecordQueryScanPlan(ScanComparisons.EMPTY, false);
    plan.logPlanStructure(timer);
    assertNoIndexes(plan);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_SCAN), 1);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Test(org.junit.jupiter.api.Test)

Example 10 with StoreTimer

use of com.apple.foundationdb.record.provider.common.StoreTimer in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method unionSameIndex.

@Test
public void unionSameIndex() {
    final RecordQueryPlan plan = RecordQueryUnionPlan.from(indexPlanEquals("index_1", 2), indexPlanEquals("index_1", 4), EmptyKeyExpression.EMPTY, false);
    assertUsesIndexes(plan, Lists.newArrayList("index_1"));
    final StoreTimer timer = new FDBStoreTimer();
    plan.logPlanStructure(timer);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_UNION), 1);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_INDEX), 2);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Test(org.junit.jupiter.api.Test)

Aggregations

StoreTimer (com.apple.foundationdb.record.provider.common.StoreTimer)11 Test (org.junit.jupiter.api.Test)10 StoreTimerSnapshot (com.apple.foundationdb.record.provider.common.StoreTimerSnapshot)5 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)5 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)5 KeyValue (com.apple.foundationdb.KeyValue)2 Transaction (com.apple.foundationdb.Transaction)1 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)1 StoreSubTimer (com.apple.foundationdb.record.provider.common.StoreSubTimer)1 IndexScanComparisons (com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons)1 IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)1 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)1 RecordQueryInValuesJoinPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryInValuesJoinPlan)1 RecordQueryIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan)1 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)1