Search in sources :

Example 11 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class LeaderboardIndexTest method parallel.

@Test
@Tag(Tags.Slow)
public void parallel() throws Exception {
    Leaderboards leaderboards = new FlatLeaderboards();
    leaderboards.buildMetaData();
    try (FDBRecordContext context = openContext()) {
        leaderboards.openRecordStore(context, true);
        leaderboards.updateWindows(true, 10100);
        context.commit();
    }
    FDBRecordStore.Builder builder = leaderboards.recordStore.asBuilder();
    parallelThread(builder, 0, 500).run();
    Thread[] threads = new Thread[2];
    Map<String, String> uncaught = new HashMap<>();
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(parallelThread(builder.copyBuilder(), i + 1, 10));
        threads[i].setUncaughtExceptionHandler((t, e) -> uncaught.put("uncaught " + t.getName(), e.toString()));
    }
    for (int i = 0; i < threads.length; i++) {
        threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) {
        threads[i].join();
    }
    final KeyValueLogMessage msg = KeyValueLogMessage.build("Results");
    msg.addKeysAndValues(metrics.getKeysAndValues());
    msg.addKeysAndValues(uncaught);
    System.out.println(msg.toString());
    assertThat(uncaught.values(), Matchers.emptyCollectionOf(String.class));
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) HashMap(java.util.HashMap) FDBRecordStore(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 12 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreTestBase method commit.

public void commit(FDBRecordContext context) {
    try {
        context.commit();
        if (logger.isInfoEnabled()) {
            KeyValueLogMessage msg = KeyValueLogMessage.build("committing transaction");
            msg.addKeysAndValues(timer.getKeysAndValues());
            logger.info(msg.toString());
        }
    } finally {
        timer.reset();
    }
}
Also used : KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage)

Example 13 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class FDBDatabaseTest method performNoOpAgainstFakeCluster.

@Test
public void performNoOpAgainstFakeCluster() throws IOException {
    final String clusterFile = FDBTestBase.createFakeClusterFile("perform_no_op_");
    final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase(clusterFile);
    // Should not be able to get a real read version from the fake cluster
    assertThrows(TimeoutException.class, () -> {
        try (FDBRecordContext context = database.openContext()) {
            context.getReadVersionAsync().get(100L, TimeUnit.MILLISECONDS);
        }
    });
    // Should still be able to perform a no-op
    FDBStoreTimer timer = new FDBStoreTimer();
    database.performNoOp(timer);
    assertEquals(1, timer.getCount(FDBStoreTimer.Events.PERFORM_NO_OP));
    assertThat(timer.getCount(FDBStoreTimer.Waits.WAIT_PERFORM_NO_OP), lessThanOrEqualTo(1));
    if (LOGGER.isInfoEnabled()) {
        KeyValueLogMessage logMessage = KeyValueLogMessage.build("performed no-op");
        logMessage.addKeysAndValues(timer.getKeysAndValues());
        LOGGER.info(logMessage.toString());
    }
}
Also used : KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class FDBDatabaseTest method performNoOp.

@Test
public void performNoOp() {
    final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
    FDBStoreTimer timer = new FDBStoreTimer();
    database.performNoOp(timer);
    assertEquals(1, timer.getCount(FDBStoreTimer.Events.PERFORM_NO_OP));
    assertThat(timer.getCount(FDBStoreTimer.Waits.WAIT_PERFORM_NO_OP), lessThanOrEqualTo(1));
    if (LOGGER.isInfoEnabled()) {
        KeyValueLogMessage logMessage = KeyValueLogMessage.build("performed no-op");
        logMessage.addKeysAndValues(timer.getKeysAndValues());
        LOGGER.info(logMessage.toString());
    }
}
Also used : KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with KeyValueLogMessage

use of com.apple.foundationdb.record.logging.KeyValueLogMessage in project fdb-record-layer by FoundationDB.

the class FDBRecordStorePerformanceTest method runTest.

protected void runTest(String title, Function<Integer, Function<FDBRecordStore, CompletableFuture<?>>> test, TestParameters parameters) {
    for (int i = 0; i < parameters.warmupCount; i++) {
        openAndRun(null, test.apply(i), parameters).join();
    }
    final FDBStoreTimer timer = new FDBStoreTimer();
    final List<Long> times = new ArrayList<>();
    if (parameters.parallelCount == 0) {
        final Function<FDBRecordStore, CompletableFuture<?>> singleTest = test.apply(parameters.startValue);
        try (FDBRecordContext context = fdb.openContext()) {
            context.setTimer(timer);
            if (databaseParameters.disableReadYourWrites) {
                context.ensureActive().options().setReadYourWritesDisable();
            }
            FDBRecordStore store = FDBRecordStore.newBuilder().setContext(context).setMetaDataProvider(metaData).setKeySpacePath(TestKeySpace.getKeyspacePath(databaseParameters.path)).setPipelineSizer(parameters).uncheckedOpen();
            for (int j = 0; j < parameters.repeatCount; j++) {
                long startTime = System.nanoTime();
                try {
                    singleTest.apply(store).get();
                } catch (Exception ex) {
                    logger.warn("error on pass " + j, ex);
                }
                times.add(System.nanoTime() - startTime);
            }
        }
    } else {
        for (int j = 0; j < parameters.repeatCount; j++) {
            List<CompletableFuture<Long>> futures = new ArrayList<>(parameters.parallelCount);
            for (int i = 0; i < parameters.parallelCount; i++) {
                futures.add(openAndRun(timer, test.apply(parameters.startValue + parameters.incrementValue * i), parameters));
            }
            for (CompletableFuture<Long> future : futures) {
                try {
                    times.add(future.get());
                } catch (Exception ex) {
                    logger.warn("error on pass " + j, ex);
                }
            }
        }
    }
    final double[] dtimes = new double[times.size()];
    for (int i = 0; i < dtimes.length; i++) {
        dtimes[i] = TimeUnit.NANOSECONDS.toMicros(times.get(i));
    }
    Arrays.sort(dtimes);
    final double min = dtimes[0];
    final double max = dtimes[dtimes.length - 1];
    final Percentile percentile = new Percentile();
    percentile.setData(dtimes);
    final double p50 = percentile.evaluate(50);
    final double p90 = percentile.evaluate(90);
    final KeyValueLogMessage msg = KeyValueLogMessage.build(title, "repeatCount", parameters.repeatCount, "parallelCount", parameters.parallelCount, "pipelineSize", parameters.pipelineSize, "min_micros", min, "max_micros", max, "p50_micros", p50, "p90_micros", p90);
    msg.addKeysAndValues(new TreeMap<>(timer.getKeysAndValues()));
    logger.info(msg.toString());
}
Also used : Percentile(org.apache.commons.math3.stat.descriptive.rank.Percentile) ArrayList(java.util.ArrayList) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) CompletableFuture(java.util.concurrent.CompletableFuture)

Aggregations

KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)22 Index (com.apple.foundationdb.record.metadata.Index)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 Nonnull (javax.annotation.Nonnull)8 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)6 MoreAsyncUtil (com.apple.foundationdb.async.MoreAsyncUtil)6 IndexState (com.apple.foundationdb.record.IndexState)6 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)6 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)6 Tuple (com.apple.foundationdb.tuple.Tuple)6 Function (java.util.function.Function)6 Nullable (javax.annotation.Nullable)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Range (com.apple.foundationdb.Range)5 Transaction (com.apple.foundationdb.Transaction)5 API (com.apple.foundationdb.annotation.API)5 RangeSet (com.apple.foundationdb.async.RangeSet)5