Search in sources :

Example 1 with StoreTimerSnapshot

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

the class FDBStoreTimerTest method timerConstraintChecks.

@Test
public void timerConstraintChecks() {
    // invalid to substract a snapshot timer from a timer that has been reset after the snapshot was taken
    FDBStoreTimer latestTimer = context.getTimer();
    final StoreTimerSnapshot savedTimer;
    savedTimer = StoreTimerSnapshot.from(latestTimer);
    latestTimer.reset();
    assertThrows(RecordCoreArgumentException.class, () -> StoreTimer.getDifference(latestTimer, savedTimer));
    // invalid to subtract a snapshot timer from a timer it was not derived from
    StoreTimer anotherStoreTimer = new StoreTimer();
    assertThrows(RecordCoreArgumentException.class, () -> StoreTimer.getDifference(anotherStoreTimer, savedTimer));
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) StoreTimerSnapshot(com.apple.foundationdb.record.provider.common.StoreTimerSnapshot) Test(org.junit.jupiter.api.Test)

Example 2 with StoreTimerSnapshot

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

the class FDBStoreTimerTest method newMetricsAddedToSnapshotDifference.

@Test
public void newMetricsAddedToSnapshotDifference() {
    StoreTimer timer = new FDBStoreTimer();
    timer.increment(FDBStoreTimer.Counts.DELETE_RECORD_KEY);
    StoreTimerSnapshot snapshot = StoreTimerSnapshot.from(timer);
    timer.increment(FDBStoreTimer.Counts.DELETE_RECORD_KEY);
    timer.record(FDBStoreTimer.Events.DIRECTORY_READ, 7L);
    StoreTimer diff = StoreTimer.getDifference(timer, snapshot);
    assertThat(diff.getCounter(FDBStoreTimer.Counts.DELETE_RECORD_KEY).getCount(), Matchers.is(1));
    assertThat(diff.getCounter(FDBStoreTimer.Counts.DELETE_RECORD_KEY).getTimeNanos(), Matchers.is(0L));
    assertThat(diff.getCounter(FDBStoreTimer.Events.DIRECTORY_READ).getCount(), Matchers.is(1));
    assertThat(diff.getCounter(FDBStoreTimer.Events.DIRECTORY_READ).getTimeNanos(), Matchers.is(7L));
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) StoreTimerSnapshot(com.apple.foundationdb.record.provider.common.StoreTimerSnapshot) Test(org.junit.jupiter.api.Test)

Example 3 with StoreTimerSnapshot

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

the class FDBStoreTimerTest method unchangedMetricsExcludedFromSnapshotDifference.

@Test
public void unchangedMetricsExcludedFromSnapshotDifference() {
    StoreTimer timer = new FDBStoreTimer();
    timer.increment(FDBStoreTimer.Counts.CREATE_RECORD_STORE);
    timer.increment(FDBStoreTimer.Counts.DELETE_RECORD_KEY);
    timer.record(FDBStoreTimer.Events.CHECK_VERSION, 1L);
    timer.record(FDBStoreTimer.Events.DIRECTORY_READ, 3L);
    StoreTimerSnapshot snapshot = StoreTimerSnapshot.from(timer);
    timer.increment(FDBStoreTimer.Counts.DELETE_RECORD_KEY);
    timer.record(FDBStoreTimer.Events.DIRECTORY_READ, 7L);
    StoreTimer diff = StoreTimer.getDifference(timer, snapshot);
    assertThat(diff.getCounter(FDBStoreTimer.Counts.CREATE_RECORD_STORE), Matchers.nullValue());
    assertThat(diff.getCounter(FDBStoreTimer.Events.CHECK_VERSION), Matchers.nullValue());
    assertThat(diff.getCounter(FDBStoreTimer.Counts.DELETE_RECORD_KEY).getCount(), Matchers.is(1));
    assertThat(diff.getCounter(FDBStoreTimer.Counts.DELETE_RECORD_KEY).getTimeNanos(), Matchers.is(0L));
    assertThat(diff.getCounter(FDBStoreTimer.Events.DIRECTORY_READ).getCount(), Matchers.is(1));
    assertThat(diff.getCounter(FDBStoreTimer.Events.DIRECTORY_READ).getTimeNanos(), Matchers.is(7L));
}
Also used : StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) StoreTimerSnapshot(com.apple.foundationdb.record.provider.common.StoreTimerSnapshot) Test(org.junit.jupiter.api.Test)

Example 4 with StoreTimerSnapshot

use of com.apple.foundationdb.record.provider.common.StoreTimerSnapshot 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 5 with StoreTimerSnapshot

use of com.apple.foundationdb.record.provider.common.StoreTimerSnapshot 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)

Aggregations

StoreTimer (com.apple.foundationdb.record.provider.common.StoreTimer)5 StoreTimerSnapshot (com.apple.foundationdb.record.provider.common.StoreTimerSnapshot)5 Test (org.junit.jupiter.api.Test)5 KeyValue (com.apple.foundationdb.KeyValue)2 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)1