Skip to content

Commit

Permalink
Added cache GET benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
vozerov-gridgain committed Feb 4, 2016
1 parent afd3bc1 commit e2be94e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
Expand Up @@ -58,6 +58,9 @@ public class JmhCacheAbstractBenchmark extends JmhAbstractBenchmark {
/** Default amount of nodes. */ /** Default amount of nodes. */
protected static final int DFLT_DATA_NODES = 1; protected static final int DFLT_DATA_NODES = 1;


/** Items count. */
protected static final int CNT = 100000;

/** IP finder shared across nodes. */ /** IP finder shared across nodes. */
private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);


Expand Down
Expand Up @@ -31,10 +31,7 @@
* Put benchmark. * Put benchmark.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class JmhCachePutBenchmark extends JmhCacheAbstractBenchmark { public class JmhCacheBenchmark extends JmhCacheAbstractBenchmark {
/** Items count. */
private static final int CNT = 100000;

/** /**
* Set up routine. * Set up routine.
* *
Expand All @@ -60,53 +57,77 @@ public void setup() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
@Benchmark @Benchmark
public void testPut() throws Exception { public void put() throws Exception {
int key = ThreadLocalRandom.current().nextInt(CNT); int key = ThreadLocalRandom.current().nextInt(CNT);


cache.put(key, new IntValue(key)); cache.put(key, new IntValue(key));
} }


/**
* Test PUT operation.
*
* @throws Exception If failed.
*/
@Benchmark
public Object get() throws Exception {
int key = ThreadLocalRandom.current().nextInt(CNT);

return cache.get(key);
}

/** /**
* Run benchmarks. * Run benchmarks.
* *
* @param args Arguments. * @param args Arguments.
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
run(CacheAtomicityMode.ATOMIC); run("put", CacheAtomicityMode.ATOMIC);
run("get", CacheAtomicityMode.ATOMIC);
run("put", CacheAtomicityMode.TRANSACTIONAL);
run("get", CacheAtomicityMode.TRANSACTIONAL);
} }


/** /**
* Run benchmarks for atomic cache. * Run benchmarks for atomic cache.
* *
* @param benchmark Benchmark name.
* @param atomicityMode Atomicity mode. * @param atomicityMode Atomicity mode.
* @throws Exception If failed. * @throws Exception If failed.
*/ */
private static void run(CacheAtomicityMode atomicityMode) throws Exception { private static void run(String benchmark, CacheAtomicityMode atomicityMode) throws Exception {
run(4, true, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); run(benchmark, 4, true, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC);
run(4, true, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); run(benchmark, 4, true, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC);
run(4, false, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); run(benchmark, 4, false, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC);
run(4, false, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC); run(benchmark, 4, false, atomicityMode, CacheWriteSynchronizationMode.FULL_SYNC);
} }


/** /**
* Run benchmark. * Run benchmark.
* *
* @param benchmark Benchmark to run.
* @param threads Amount of threads.
* @param client Client mode flag. * @param client Client mode flag.
* @param atomicityMode Atomicity mode.
* @param writeSyncMode Write synchronization mode. * @param writeSyncMode Write synchronization mode.
* @throws Exception If failed. * @throws Exception If failed.
*/ */
private static void run(int threads, boolean client, CacheAtomicityMode atomicityMode, private static void run(String benchmark, int threads, boolean client, CacheAtomicityMode atomicityMode,
CacheWriteSynchronizationMode writeSyncMode) throws Exception { CacheWriteSynchronizationMode writeSyncMode) throws Exception {
String output = "ignite-cache-put-" + threads + "-threads-" + (client ? "client" : "data") + String simpleClsName = JmhCacheBenchmark.class.getSimpleName();
"-" + atomicityMode + "-" + writeSyncMode;
String output = simpleClsName + "-" + benchmark +
"-" + threads + "-threads" +
"-" + (client ? "client" : "data") +
"-" + atomicityMode +
"-" + writeSyncMode;


JmhIdeBenchmarkRunner.create() JmhIdeBenchmarkRunner.create()
.forks(1) .forks(1)
.threads(threads) .threads(threads)
.warmupIterations(10) .warmupIterations(10)
.measurementIterations(60) .measurementIterations(60)
.classes(JmhCachePutBenchmark.class) .benchmarks(simpleClsName + "." + benchmark)
.output(output + ".jmh.log") .output(output + ".jmh.log")
.profilers(GCProfiler.class) .profilers(GCProfiler.class)
.jvmArguments( .jvmArguments(
Expand Down
Expand Up @@ -42,8 +42,8 @@ public class JmhIdeBenchmarkRunner {
/** Output time unit. */ /** Output time unit. */
private TimeUnit outputTimeUnit = TimeUnit.SECONDS; private TimeUnit outputTimeUnit = TimeUnit.SECONDS;


/** Classes to run. */ /** Benchmarks to run. */
private Class[] clss; private Object[] benchmarks;


/** JVM arguments. */ /** JVM arguments. */
private String[] jvmArgs; private String[] jvmArgs;
Expand Down Expand Up @@ -123,11 +123,11 @@ public JmhIdeBenchmarkRunner outputTimeUnit(TimeUnit outputTimeUnit) {
} }


/** /**
* @param clss Classes. * @param benchmarks Benchmarks.
* @return This instance. * @return This instance.
*/ */
public JmhIdeBenchmarkRunner classes(Class... clss) { public JmhIdeBenchmarkRunner benchmarks(Object... benchmarks) {
this.clss = clss; this.benchmarks = benchmarks;


return this; return this;
} }
Expand Down Expand Up @@ -191,9 +191,13 @@ public OptionsBuilder optionsBuilder() {
builder.getBenchModes().add(benchmarkMode); builder.getBenchModes().add(benchmarkMode);
} }


if (clss != null) { if (benchmarks != null) {
for (Class cls : clss) for (Object benchmark : benchmarks) {
builder.include(cls.getSimpleName()); if (benchmark instanceof Class)
builder.include(((Class)benchmark).getSimpleName());
else
builder.include(benchmark.toString());
}
} }


if (jvmArgs != null) if (jvmArgs != null)
Expand Down

0 comments on commit e2be94e

Please sign in to comment.