From 0ddde0a9c5ed87c7290faf2af0a882a6683b40f5 Mon Sep 17 00:00:00 2001
From: nprentza <90831697+nprentza@users.noreply.github.com>
Date: Thu, 19 Oct 2023 13:06:57 +0300
Subject: [PATCH] DROOLS-7573 - add parameter for h2vm/infinispan store (#268)
* add parameter for h2vm/infinispan store
* add 'h2vmstore' option in Mode parameter
* a fix for InsertOnlyBenchmark
---
.../drools-benchmarks-reliability/pom.xml | 4 +
.../AbstractReliabilityBenchmark.java | 94 ++++++++++++++-----
.../reliability/FireAndAlarmBenchmark.java | 2 +-
.../InsertFailoverFireBenchmark.java | 18 ++--
4 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml b/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
index 7f8e25b3..33c88296 100644
--- a/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
+++ b/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
@@ -47,6 +47,10 @@
org.drools
drools-reliability-infinispan
+
+ org.drools
+ drools-reliability-h2mvstore
+
org.infinispan
infinispan-server-testdriver-core
diff --git a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmark.java b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmark.java
index cd3be3cf..c39b6400 100644
--- a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmark.java
+++ b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmark.java
@@ -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;
@@ -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;
@@ -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"})
@@ -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);
+ }
}
}
@@ -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();
}
@@ -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");
+ }
}
\ No newline at end of file
diff --git a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/FireAndAlarmBenchmark.java b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/FireAndAlarmBenchmark.java
index c9eeb422..ecfa1a38 100644
--- a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/FireAndAlarmBenchmark.java
+++ b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/FireAndAlarmBenchmark.java
@@ -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"})
diff --git a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java
index 21122a98..cd633c5f 100644
--- a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java
+++ b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java
@@ -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"})
@@ -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;
@@ -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();
+ }
}