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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations