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