Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Feature/dynamic column gets perf test (#731)
Browse files Browse the repository at this point in the history
* First cut at dynamic gets

* get first column explicitly

* - Refactored KvsGetDynamicBenchmarks:
	- Removed correctness checks.
	- Moved key-generation to setup.
	- Increased number of warmups and iterations (note that local results
	  showed suspiciously consistant results).
- Updated docker-compose-rule to version that includes Bobby's thread
  leak fix.
- Supressed unimportant logging.

* - Moved from `Mode.AverageTime` -> `Mode.SampleTime`.
- Cleaned up unused imports.

* - Removed BlackHole consumption of results (only reccomended if multiple
  variables need to be consumed for benchmarking.

* - Changed State scope to Benchmark.
- Removed "unused" (outside of comment) import so Circle CI passed.

* Implicit and explicit getting of columns
  • Loading branch information
davidscottcohen authored and rjullman committed Sep 12, 2016
1 parent 4611856 commit fe3eb06
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public static TableReference createTable(KeyValueService kvs, String tableName,
return tableRef;
}



public static TableReference createTableWithDynamicColumns(KeyValueService kvs, String tableName, String rowComponent, String columnComponent) {
TableReference tableRef = TableReference.createFromFullyQualifiedName(tableName);
TableDefinition tableDef = new TableDefinition() {{
rowName();
rowComponent(rowComponent, ValueType.STRING);
dynamicColumns();
columnComponent(columnComponent, ValueType.FIXED_LONG);
value(ValueType.FIXED_LONG);
conflictHandler(ConflictHandler.IGNORE_ALL);
sweepStrategy(TableMetadataPersistence.SweepStrategy.NOTHING);
}};
kvs.createTable(tableRef, tableDef.toTableMetadata().persistToBytes());
return tableRef;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.palantir.atlasdb.performance.benchmarks;

import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;
import com.palantir.atlasdb.keyvalue.api.Cell;
import com.palantir.atlasdb.keyvalue.api.ColumnSelection;
import com.palantir.atlasdb.keyvalue.api.KeyValueService;
import com.palantir.atlasdb.keyvalue.api.TableReference;
import com.palantir.atlasdb.keyvalue.api.Value;
import com.palantir.atlasdb.performance.backend.KeyValueServiceConnector;

/**
* Performance benchmarks for KVS get with dynamic columns.
*
* @author coda
*
*/
@State(Scope.Benchmark)
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 1, time = 5, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 1, time = 30, timeUnit = TimeUnit.SECONDS)
public class KvsGetDynamicBenchmarks {

private static final String TABLE_NAME_1 = "performance.table2";
private static final String ROW_COMPONENT = "BIG_ROW_OF_INTS";
private static final String COLUMN_COMPONENT = "col";
private static final long DUMMY_TIMESTAMP = 1L;
private static final long READ_TIMESTAMP = 2L;

private final int NUM_COLS = 50000;

private KeyValueServiceConnector connector;
private KeyValueService kvs;

private TableReference tableRef1;

private Map<Cell, Long> allCells2ReadTimestamp;
private Map<Cell, Long> firstCell2ReadTimestamp;

@Setup
public void setup(KeyValueServiceConnector connector) throws UnsupportedEncodingException {
this.connector = connector;
kvs = connector.connect();
tableRef1 = KvsBenchmarks.createTableWithDynamicColumns(kvs, TABLE_NAME_1, ROW_COMPONENT, COLUMN_COMPONENT);
byte[] rowBytes = ROW_COMPONENT.getBytes("UTF-8");
Map<Cell,byte[]> values = Maps.newHashMap();
allCells2ReadTimestamp = Maps.newHashMap();
firstCell2ReadTimestamp = ImmutableMap.of(Cell.create(rowBytes, ("col_0").getBytes("UTF-8")), READ_TIMESTAMP);
for (int i = 0; i < NUM_COLS; i++) {
Cell c = Cell.create(rowBytes, ("col_"+i).getBytes("UTF-8"));
values.put(c, Ints.toByteArray(i));
allCells2ReadTimestamp.put(c, READ_TIMESTAMP);
}
kvs.put(tableRef1, values, DUMMY_TIMESTAMP);
}

@TearDown
public void cleanup() throws Exception {
kvs.dropTables(Sets.newHashSet(tableRef1));
kvs.close();
connector.close();
}

@Benchmark
public Map<Cell, Value> getAllColumnsExplicitly() {
Map<Cell, Value> result = kvs.get(tableRef1, allCells2ReadTimestamp);
KvsBenchmarks.validate(result.size() == NUM_COLS, "Should be %s columns, but were: %s", NUM_COLS, result.size());
return result;
}

@Benchmark
public Map<Cell, Value> getAllColumnsImplicitly() throws UnsupportedEncodingException {
Map<Cell, Value> result = kvs.getRows(tableRef1, Collections.singleton(ROW_COMPONENT.getBytes("UTF-8")), ColumnSelection.all(), READ_TIMESTAMP);
KvsBenchmarks.validate(result.size() == NUM_COLS, "Should be %s columns, but were: %s", NUM_COLS, result.size());
return result;
}


@Benchmark
public Map<Cell, Value> getFirstColumnExplicitly() {
Map<Cell, Value> result = kvs.get(tableRef1, firstCell2ReadTimestamp);
KvsBenchmarks.validate(result.size() == 1, "Should be %s column, but were: %s", 1, result.size());
int value = Ints.fromByteArray(Iterables.getOnlyElement(result.values()).getContents());
KvsBenchmarks.validate(value == 0, "Value should be %s but is %s", 0, value);
return result;
}


@Benchmark
public Map<Cell, Value> getFirstColumnExplicitlyGetRows() throws UnsupportedEncodingException {
Map<Cell, Value> result = kvs.getRows(tableRef1, Collections.singleton(ROW_COMPONENT.getBytes("UTF-8")),
ColumnSelection.create(
firstCell2ReadTimestamp.keySet().stream().map(Cell::getColumnName).collect(Collectors.toList())
),
READ_TIMESTAMP);
KvsBenchmarks.validate(result.size() == 1, "Should be %s column, but were: %s", 1, result.size());
int value = Ints.fromByteArray(Iterables.getOnlyElement(result.values()).getContents());
KvsBenchmarks.validate(value == 0, "Value should be %s but is %s", 0, value);
return result;
}

}
3 changes: 3 additions & 0 deletions atlasdb-perf/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>

<logger name="com.palantir.nexus.db.pool.HikariCPConnectionManager" level="ERROR"/>
<logger name="com.palantir.docker.compose.logging.FileLogCollector" level="ERROR"/>
</configuration>

0 comments on commit fe3eb06

Please sign in to comment.