Skip to content

Commit

Permalink
Create separate test/benchmarks folder
Browse files Browse the repository at this point in the history
* Update the `jmh.sh` script and create a `test-run.sh` script.
* Update the `DataReplicationBenchmark` to point to something other than
  a tmpfs.
* Move the existing benchmarks.
  • Loading branch information
jabolina committed Jun 9, 2024
1 parent 05fdb17 commit 8741b8b
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 191 deletions.
31 changes: 17 additions & 14 deletions bin/jmh.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/bin/bash

BASEDIR=$(dirname $0)
ROOTDIR=$(realpath ${BASEDIR}/..)
LIBS="${ROOTDIR}/target/libs"
CLASSES="${ROOTDIR}/target/classes"
TEST_CLASSES="${ROOTDIR}/target/test-classes"
CONFDIR="${ROOTDIR}/conf"
BASEDIR=$(dirname "$0")

function help() {
echo "$@"
echo ""
echo "tip: run '$0 -h' for JMH options"
echo "tip: pass '-h' for JMH options"
exit 1
}

function check_if_exists_or_exit() {
[ ! -d "$@" ] && help "Missing '$@' directory. Run: 'mvn clean package -DskipTests' before running the JMH benchmark"
function list_benchmarks() {
echo "Available benchmarks:"
printf "\tDataReplicationBenchmark\n"
printf "\tLogJmhBenchmark\n"
printf "\tStorageAppenderBenchmark\n"
help;
}

check_if_exists_or_exit ${LIBS}
check_if_exists_or_exit ${CLASSES}
check_if_exists_or_exit ${TEST_CLASSES}
BENCHMARK="$1"
shift;

java -cp "${LIBS}/*":${CLASSES}:${TEST_CLASSES}:${CONFDIR} ${JAVA_OPTIONS} org.openjdk.jmh.Main org.jgroups.perf.LogJmhBenchmark $@
if [ "$BENCHMARK" = "-list" ]; then
list_benchmarks
exit 0;
fi

# shellcheck disable=SC2086,SC2048
"$BASEDIR"/test-run.sh -ea org.openjdk.jmh.Main "$BENCHMARK" $*
39 changes: 39 additions & 0 deletions bin/test-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Same as `run.sh` but for running classes in the test sources.

function check_if_exists_or_exit() {
[ ! -d "$@" ] && help "Missing '$@' directory. Run: 'mvn clean package -DskipTests' before running"
}

MCAST_ADDR=232.5.5.5
BIN_DIR=$(dirname "$0")

# Project built with Maven.
LIB=${BIN_DIR}/../target/libs
CLASSES=${BIN_DIR}/../target/classes
TEST_CLASSES=${BIN_DIR}/../target/test-classes
CONF=${BIN_DIR}/../conf

check_if_exists_or_exit ${LIBS}
check_if_exists_or_exit ${CLASSES}
check_if_exists_or_exit ${TEST_CLASSES}

CP="$CLASSES:$CONF:$TEST_CLASSES:$LIB/*"
LOG="-Dlog4j.configurationFile=log4j2.xml"

JG_FLAGS="-Djgroups.udp.mcast_addr=$MCAST_ADDR"
JG_FLAGS="$JG_FLAGS -Djava.net.preferIPv4Stack=true"

FLAGS="-server -Xmx600M -Xms600M"
FLAGS="$FLAGS -XX:CompileThreshold=10000 -XX:ThreadStackSize=64K -XX:SurvivorRatio=8"
FLAGS="$FLAGS -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15"
FLAGS="$FLAGS -Xshare:off"

#GC="-XX:+UseParNewGC -XX:+UseConcMarkSweepGC" ## concurrent mark and sweep (CMS) collector

EXPERIMENTAL="$EXPERIMENTAL -XX:+EliminateLocks"
#DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8787"

# shellcheck disable=SC2086,SC2048
java -cp $CP $DEBUG $LOG $GC $JG_FLAGS $FLAGS $EXPERIMENTAL $JAVA_OPTIONS $*
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,25 @@
<configuration>
<sources>
<source>tests/junit-functional</source>
<source>tests/benchmark</source>
</sources>
</configuration>
</execution>

<execution>
<id>add-test-configurations</id>
<phase>validate</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>tests/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

Expand Down
4 changes: 4 additions & 0 deletions src/org/jgroups/protocols/raft/RAFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public int processingQueueSize() {
public boolean synchronous() {return synchronous;}
public RAFT synchronous(boolean b) {synchronous=b; return this;}

public RAFT logDir(String logDir) {
this.log_dir = logDir;
return this;
}

public void resetStats() {
super.resetStats();
Expand Down
39 changes: 0 additions & 39 deletions tests/benchmark/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jgroups.raft;
package org.jgroups.perf;

import org.jgroups.JChannel;
import org.jgroups.protocols.raft.FileBasedLog;
import org.jgroups.protocols.raft.RAFT;
import org.jgroups.raft.RaftHandle;
import org.jgroups.raft.StateMachine;
import org.jgroups.raft.testfwk.RaftTestUtils;
import org.jgroups.util.Util;

Expand Down Expand Up @@ -38,7 +40,7 @@
@BenchmarkMode({Mode.Throughput})
@Warmup(iterations = 10, time = 5)
@Measurement(iterations = 5, time = 10)
@Fork(value = 3, jvmArgsPrepend = "-Djava.net.preferIPv4Stack=true -Djgroups.udp.ip_ttl=0")
@Fork(value = 3, jvmArgsPrepend = "-Djava.net.preferIPv4Stack=true -Djgroups.udp.ip_ttl=0 -Djmh.executor=PLATFORM")
public class DataReplicationBenchmark {

@Benchmark
Expand Down Expand Up @@ -79,7 +81,7 @@ public void initialize() throws Exception {
String name = Character.toString('A' + i);

// Utilize the default configuration shipped with jgroups-raft.
JChannel ch = new JChannel("raft.xml");
JChannel ch = new JChannel("raft-benchmark.xml");
ch.name(name);

// A no-op state machine.
Expand All @@ -91,8 +93,9 @@ public void initialize() throws Exception {
raft.members(memberList);

// Fine-tune the RAFT protocol below.
raft.logClass(FileBasedLog.class.getCanonicalName());
raft.logUseFsync(useFsync);
raft.logClass(FileBasedLog.class.getCanonicalName())
.logDir(String.format("%s/target/benchmark", System.getProperty("user.dir")))
.logUseFsync(useFsync);

members[i] = handler;
ch.connect("jmh-replication");
Expand Down Expand Up @@ -145,7 +148,8 @@ public EmptyStateMachine(int dataSize) {

@Override
public byte[] apply(byte[] data, int offset, int length, boolean serialize_response) throws Exception {
if (data.length != dataSize) throw new IllegalArgumentException("Data size does not match");
if (data.length != dataSize)
throw new IllegalArgumentException(String.format("Data size does not match: %d != %d", data.length, dataSize));

return RESPONSE;
}
Expand Down
132 changes: 0 additions & 132 deletions tests/benchmark/pom.xml

This file was deleted.

Loading

0 comments on commit 8741b8b

Please sign in to comment.