Skip to content

Commit

Permalink
DROOLS-7573 - add parameter for h2vm/infinispan store (#268)
Browse files Browse the repository at this point in the history
* add parameter for h2vm/infinispan store

* add 'h2vmstore' option in Mode parameter

* a fix for InsertOnlyBenchmark
  • Loading branch information
nprentza authored Oct 19, 2023
1 parent 96f62f7 commit 0ddde0a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<groupId>org.drools</groupId>
<artifactId>drools-reliability-infinispan</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-reliability-h2mvstore</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-testdriver-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

import org.drools.benchmarks.common.AbstractBenchmark;
import org.drools.benchmarks.common.util.RuntimeUtil;
import org.drools.reliability.core.ReliableGlobalResolverFactory;
import org.drools.reliability.core.SimpleReliableObjectStoreFactory;
import org.drools.reliability.core.StorageManagerFactory;
import org.drools.reliability.h2mvstore.H2MVStoreStorageManager;
import org.drools.reliability.infinispan.InfinispanStorageManager;
import org.drools.reliability.infinispan.InfinispanStorageManagerFactory;
import org.drools.util.FileUtils;
Expand All @@ -33,23 +36,26 @@
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;

import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.EMBEDDED;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.INFINISPAN_EMBEDDED;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.NONE;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.REMOTE;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.REMOTEPROTO;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.INFINISPAN_REMOTE;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.INFINISPAN_REMOTEPROTO;
import static org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mode.H2MVSTORE;
import static org.drools.reliability.infinispan.EmbeddedStorageManager.GLOBAL_STATE_DIR;
import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.INFINISPAN_STORAGE_ALLOWED_PACKAGES;
import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.INFINISPAN_STORAGE_MARSHALLER;
import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.INFINISPAN_STORAGE_MODE;
import static org.drools.util.Config.getConfig;

public abstract class AbstractReliabilityBenchmark extends AbstractBenchmark {

// infinispanStorageMode has to match InfinispanStorageManagerFactory.INFINISPAN_STORAGE_MODE
public enum Mode {
NONE(null),
EMBEDDED("EMBEDDED"),
REMOTE("REMOTE"),
REMOTEPROTO("REMOTE");
INFINISPAN_EMBEDDED("EMBEDDED"),
INFINISPAN_REMOTE("REMOTE"),
INFINISPAN_REMOTEPROTO("REMOTE"),
H2MVSTORE("H2MVSTORE");

private String infinispanStorageMode;

Expand All @@ -62,7 +68,14 @@ public String getInfinispanStorageMode() {
}
}

@Param({"NONE", "EMBEDDED", "REMOTE", "REMOTEPROTO"})
public enum Module {
INFINISPAN,
H2MVSTORE
}

public static final String DROOLS_RELIABILITY_MODULE_TEST = "drools.reliability.module.test";

@Param({"NONE", "INFINISPAN_EMBEDDED", "INFINISPAN_REMOTE", "INFINISPAN_REMOTEPROTO", "H2MVSTORE"})
protected Mode mode;

@Param({"true", "false"})
Expand All @@ -74,25 +87,34 @@ public String getInfinispanStorageMode() {
public void setupEnvironment() {
FileUtils.deleteDirectory(Path.of(GLOBAL_STATE_DIR));

if (mode != NONE) {
System.setProperty(INFINISPAN_STORAGE_MODE, mode.getInfinispanStorageMode());
}
if (mode == H2MVSTORE){
H2MVStoreStorageManager.cleanUpDatabase();
System.setProperty(DROOLS_RELIABILITY_MODULE_TEST, "H2MVSTORE");
configureServicePriorities();
}else {
System.setProperty(DROOLS_RELIABILITY_MODULE_TEST, "INFINISPAN");
if (mode != NONE) {
System.setProperty(INFINISPAN_STORAGE_MODE, mode.getInfinispanStorageMode());
}

if (mode == EMBEDDED || mode == REMOTE) {
System.setProperty(INFINISPAN_STORAGE_ALLOWED_PACKAGES, "org.drools.benchmarks.common.model");
}
if (mode == INFINISPAN_EMBEDDED || mode == INFINISPAN_REMOTE) {
System.setProperty(INFINISPAN_STORAGE_ALLOWED_PACKAGES, "org.drools.benchmarks.common.model");
}

if (mode == REMOTEPROTO) {
System.setProperty(INFINISPAN_STORAGE_MARSHALLER, "PROTOSTREAM");
setupSerializationContext();
}
if (mode == INFINISPAN_REMOTEPROTO) {
System.setProperty(INFINISPAN_STORAGE_MARSHALLER, "PROTOSTREAM");
setupSerializationContext();
}

configureServicePriorities();

if (mode == REMOTE || mode == REMOTEPROTO) {
container = new InfinispanContainer();
container.start();
InfinispanStorageManager storageManager = (InfinispanStorageManager) StorageManagerFactory.get().getStorageManager();
RemoteCacheManager remoteCacheManager = container.getRemoteCacheManager(storageManager.provideAdditionalRemoteConfigurationBuilder());
storageManager.setRemoteCacheManager(remoteCacheManager);
if (mode == INFINISPAN_REMOTE || mode == INFINISPAN_REMOTEPROTO) {
container = new InfinispanContainer();
container.start();
InfinispanStorageManager storageManager = (InfinispanStorageManager) StorageManagerFactory.get().getStorageManager();
RemoteCacheManager remoteCacheManager = container.getRemoteCacheManager(storageManager.provideAdditionalRemoteConfigurationBuilder());
storageManager.setRemoteCacheManager(remoteCacheManager);
}
}
}

Expand All @@ -104,7 +126,7 @@ protected void setupSerializationContext() {

@TearDown
public void tearDownEnvironment() {
if (mode == REMOTE || mode == REMOTEPROTO) {
if (mode == Mode.INFINISPAN_REMOTE || mode == Mode.INFINISPAN_REMOTEPROTO) {
StorageManagerFactory.get().getStorageManager().close();
container.stop();
}
Expand All @@ -127,4 +149,28 @@ public void setup() {
}

protected abstract void populateKieSessionPerIteration();


public static void configureServicePriorities() {
Module module = Module.valueOf(getConfig(DROOLS_RELIABILITY_MODULE_TEST, Module.INFINISPAN.name()));
if (module == Module.INFINISPAN) {
prioritizeInfinispanServices();
} else if (module == Module.H2MVSTORE) {
prioritizeH2MVStoreServices();
} else {
throw new IllegalStateException("Unknown module: " + module);
}
}

private static void prioritizeInfinispanServices() {
ReliableGlobalResolverFactory.get("infinispan");
SimpleReliableObjectStoreFactory.get("infinispan");
StorageManagerFactory.get("infinispan");
}

private static void prioritizeH2MVStoreServices() {
ReliableGlobalResolverFactory.get("core");
SimpleReliableObjectStoreFactory.get("core");
StorageManagerFactory.get("h2mvstore");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class FireAndAlarmBenchmark extends AbstractReliabilityBenchmark{
@Param({"100"})
private int factsNr;

@Param({"EMBEDDED"})
@Param({"INFINISPAN_EMBEDDED"})
private Mode mode;

@Param({"true", "false"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class InsertFailoverFireBenchmark extends AbstractReliabilityBenchmarkFai
@Param({"100"})
private int factsNr;

@Param({"EMBEDDED"})
@Param({"INFINISPAN_EMBEDDED", "H2MVSTORE"})
private Mode mode;

@Param({"true", "false"})
Expand All @@ -63,7 +63,7 @@ public void setupKieBase() {

@Setup(Level.Iteration)
public void setupAndFailover() {
System.out.println("setupAndFailover!!");
// System.out.println("setupAndFailover!!");
if (mode != Mode.NONE) {
persistenceStrategy = PersistedSessionOption.PersistenceStrategy.STORES_ONLY;
safepointStrategy = useSafepoints ? PersistedSessionOption.SafepointStrategy.AFTER_FIRE : PersistedSessionOption.SafepointStrategy.ALWAYS;
Expand Down Expand Up @@ -110,18 +110,20 @@ public long test() {
public static void main(String[] args) {
InsertFailoverFireBenchmark benchmark = new InsertFailoverFireBenchmark();
benchmark.factsNr = 10;
benchmark.mode = Mode.EMBEDDED;
benchmark.mode = Mode.H2MVSTORE;
benchmark.useObjectStoreWithReferences = true;
benchmark.useSafepoints = true;

benchmark.setupKieBase();
benchmark.setupAndFailover();
benchmark.test();
benchmark.tearDown();

benchmark.setupEnvironment(benchmark.mode);
benchmark.setupKieBase();
benchmark.setupAndFailover();
benchmark.test();
benchmark.tearDown();
}

// this method is only used by main
protected void setupEnvironment(Mode mode) {
super.mode = mode;
super.setupEnvironment();
}
}

0 comments on commit 0ddde0a

Please sign in to comment.