This is an automated email from the ASF dual-hosted git repository.
mariofusco pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-benchmarks.git
The following commit(s) were added to refs/heads/main by this push:
new cc89965d DROOLS-7543 : benchmark to test session restore after
failover (#266)
cc89965d is described below
commit cc89965dd9994eb02e69c8c70448cb7cc15cf865
Author: nprentza <[email protected]>
AuthorDate: Fri Oct 13 09:35:15 2023 +0300
DROOLS-7543 : benchmark to test session restore after failover (#266)
* InsertFailoverFireBenchmark
* PR comments
---
.../drools-benchmarks-reliability/pom.xml | 2 +-
.../reliability/AbstractReliabilityBenchmark.java | 7 +-
...bstractReliabilityBenchmarkFailoverSupport.java | 83 ++++++++++++++
.../reliability/FireAndAlarmBenchmark.java | 2 +-
.../reliability/InsertFailoverFireBenchmark.java | 127 +++++++++++++++++++++
.../AbstractSimpleFusionRuntimeBenchmark.java | 1 -
6 files changed, 216 insertions(+), 6 deletions(-)
diff --git a/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
b/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
index adca1bac..7f8e25b3 100644
--- a/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
+++ b/drools-benchmarks-parent/drools-benchmarks-reliability/pom.xml
@@ -13,7 +13,7 @@
<name>Drools 8 Benchmarks comparing reliability performance</name>
<properties>
- <version.infinispan>14.0.6.Final</version.infinispan>
+ <version.infinispan>14.0.13.Final</version.infinispan>
</properties>
<dependencyManagement>
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 4b5f9a6d..cd3be3cf 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
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+
package org.drools.benchmarks.reliability;
import java.nio.file.Path;
@@ -62,12 +63,12 @@ public abstract class AbstractReliabilityBenchmark extends
AbstractBenchmark {
}
@Param({"NONE", "EMBEDDED", "REMOTE", "REMOTEPROTO"})
- private Mode mode;
+ protected Mode mode;
@Param({"true", "false"})
- private boolean useSafepoints;
+ protected boolean useSafepoints;
- private InfinispanContainer container;
+ protected InfinispanContainer container;
@Setup
public void setupEnvironment() {
diff --git
a/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmarkFailoverSupport.java
b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmarkFailoverSupport.java
new file mode 100644
index 00000000..54f2be6b
--- /dev/null
+++
b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmarkFailoverSupport.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2023 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.benchmarks.reliability;
+
+import org.drools.reliability.core.ReliableKieSession;
+import org.drools.reliability.core.ReliableRuntimeComponentFactoryImpl;
+import org.drools.reliability.core.StorageManagerFactory;
+import org.drools.reliability.core.TestableStorageManager;
+import org.drools.reliability.infinispan.InfinispanStorageManager;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.kie.api.KieServices;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.KieSessionConfiguration;
+import org.kie.api.runtime.conf.PersistedSessionOption;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+
+public abstract class AbstractReliabilityBenchmarkFailoverSupport extends
AbstractReliabilityBenchmark{
+
+ protected Long persistedSessionId;
+ protected PersistedSessionOption.PersistenceStrategy persistenceStrategy;
// used strategy throughout the benchmark
+ protected PersistedSessionOption.SafepointStrategy safepointStrategy;
+ protected PersistedSessionOption.PersistenceObjectsStrategy
persistenceObjectsStrategy;
+
+ @Setup(Level.Iteration)
+ @Override
+ public void setup() {
+ // overriding setup() because failover scenario requires more
complicated iteration setup
+ }
+
+ protected abstract void setupKieBase();
+ protected abstract void populateKieSessionPerIteration();
+
+ protected KieSession createKieSession(PersistedSessionOption
persistedSessionOption) {
+ KieSessionConfiguration conf =
KieServices.get().newKieSessionConfiguration();
+ if (persistedSessionOption != null) {
+ conf.setOption(persistedSessionOption);
+ }
+ KieSession session = kieBase.newKieSession(conf, null);
+ this.persistedSessionId = persistedSessionOption == null ||
persistedSessionOption.isNewSession() ? session.getIdentifier() :
persistedSessionOption.getSessionId();
+ return session;
+ }
+
+ protected KieSession restoreSession() {
+ return
createKieSession(PersistedSessionOption.fromSession(persistedSessionId)
+ .withPersistenceStrategy(persistenceStrategy)
+ .withSafepointStrategy(safepointStrategy)
+ .withPersistenceObjectsStrategy(persistenceObjectsStrategy));
+ }
+
+ public void failover() {
+ // EXPLICIT is not used for now, because if useSafepoints then
strategy is always SafepointStrategy.AFTER_FIRE
+ if (safepointStrategy ==
PersistedSessionOption.SafepointStrategy.EXPLICIT) {
+ ((ReliableKieSession)kieSession).safepoint();
+ }
+
+ if (((TestableStorageManager)
StorageManagerFactory.get().getStorageManager()).isRemote()) {
+ // fail-over means restarting Drools instance. Assuming remote
infinispan keeps alive
+ StorageManagerFactory.get().getStorageManager().close(); // close
remoteCacheManager
+ // Reclaim RemoteCacheManager
+ InfinispanStorageManager cacheManager = (InfinispanStorageManager)
StorageManagerFactory.get().getStorageManager();
+ RemoteCacheManager remoteCacheManager =
container.getRemoteCacheManager(cacheManager.provideAdditionalRemoteConfigurationBuilder());
+ cacheManager.setRemoteCacheManager(remoteCacheManager);
+ } else {
+ ((TestableStorageManager)
StorageManagerFactory.get().getStorageManager()).restart(); // restart embedded
infinispan cacheManager. GlobalState and FireStore are kept
+ }
+ ReliableRuntimeComponentFactoryImpl.refreshCounterUsingStorage();
+ }
+}
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 00f41a84..c9eeb422 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
@@ -30,7 +30,7 @@ import static
org.drools.benchmarks.reliability.AbstractReliabilityBenchmark.Mod
@Measurement(iterations = 1000)
public class FireAndAlarmBenchmark extends AbstractReliabilityBenchmark{
- private static final String FIRE_AND_ALARM =
+ public static final String FIRE_AND_ALARM =
"import " + Alarm.class.getCanonicalName() + ";" +
"import " + Fire.class.getCanonicalName() + ";" +
"import " + Sprinkler.class.getCanonicalName() + ";" +
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
new file mode 100644
index 00000000..21122a98
--- /dev/null
+++
b/drools-benchmarks-parent/drools-benchmarks-reliability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2023 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.benchmarks.reliability;
+
+import org.drools.benchmarks.common.util.BuildtimeUtil;
+import org.drools.benchmarks.common.util.RuntimeUtil;
+import org.drools.benchmarks.reliability.fireandalarm.Fire;
+import org.drools.benchmarks.reliability.fireandalarm.Room;
+import org.drools.benchmarks.reliability.fireandalarm.Sprinkler;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.runtime.conf.PersistedSessionOption;
+import org.kie.internal.conf.ParallelExecutionOption;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static
org.drools.benchmarks.reliability.FireAndAlarmBenchmark.FIRE_AND_ALARM;
+
+@Warmup(iterations = 0)
+@Measurement(iterations = 1)
+public class InsertFailoverFireBenchmark extends
AbstractReliabilityBenchmarkFailoverSupport {
+
+ @Param({"100"})
+ private int factsNr;
+
+ @Param({"EMBEDDED"})
+ private Mode mode;
+
+ @Param({"true", "false"})
+ private boolean useObjectStoreWithReferences;
+
+ @Param({"true", "false"})
+ private boolean useSafepoints;
+
+ @Setup
+ @Override
+ public void setupKieBase() {
+ kieBase = BuildtimeUtil.createKieBaseFromDrl(true, FIRE_AND_ALARM,
+ ParallelExecutionOption.SEQUENTIAL,
+ EventProcessingOption.CLOUD);
+ }
+
+
+ @Setup(Level.Iteration)
+ public void setupAndFailover() {
+ System.out.println("setupAndFailover!!");
+ if (mode != Mode.NONE) {
+ persistenceStrategy =
PersistedSessionOption.PersistenceStrategy.STORES_ONLY;
+ safepointStrategy = useSafepoints ?
PersistedSessionOption.SafepointStrategy.AFTER_FIRE :
PersistedSessionOption.SafepointStrategy.ALWAYS;
+ persistenceObjectsStrategy = useObjectStoreWithReferences ?
PersistedSessionOption.PersistenceObjectsStrategy.OBJECT_REFERENCES :
PersistedSessionOption.PersistenceObjectsStrategy.SIMPLE;
+
+ // These 3 strategies will not change during the benchmark
+ PersistedSessionOption persistedSessionOption =
PersistedSessionOption.newSession()
+ .withPersistenceStrategy(persistenceStrategy)
+ .withSafepointStrategy(safepointStrategy)
+
.withPersistenceObjectsStrategy(persistenceObjectsStrategy);
+ kieSession = createKieSession(persistedSessionOption);
+ } else {
+ kieSession = RuntimeUtil.createKieSession(kieBase);
+ }
+ populateKieSessionPerIteration();
+
+ kieSession.fireAllRules();
+
+ // failover
+ failover();
+
+ // recreate kieBase
+ setupKieBase();
+ }
+
+ @Override
+ protected void populateKieSessionPerIteration() {
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < factsNr; i++) {
+ rooms.add(new Room("room_" + i));
+ kieSession.insert(rooms.get(i));
+ kieSession.insert(new Fire(rooms.get(i)));
+ kieSession.insert(new Sprinkler(rooms.get(i)));
+ }
+ }
+
+ @Benchmark
+ public long test() {
+ kieSession = restoreSession();
+ //System.out.println("restored : facts size = " +
kieSession.getFactHandles().size());
+ return kieSession.getIdentifier();
+ }
+
+ public static void main(String[] args) {
+ InsertFailoverFireBenchmark benchmark = new
InsertFailoverFireBenchmark();
+ benchmark.factsNr = 10;
+ benchmark.mode = Mode.EMBEDDED;
+ benchmark.useObjectStoreWithReferences = true;
+ benchmark.useSafepoints = true;
+
+ benchmark.setupKieBase();
+ benchmark.setupAndFailover();
+ benchmark.test();
+ benchmark.tearDown();
+
+ benchmark.setupKieBase();
+ benchmark.setupAndFailover();
+ benchmark.test();
+ benchmark.tearDown();
+ }
+}
diff --git
a/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/turtle/runtime/AbstractSimpleFusionRuntimeBenchmark.java
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/turtle/runtime/AbstractSimpleFusionRuntimeBenchmark.java
index 8c2de0e8..1af92bf6 100644
---
a/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/turtle/runtime/AbstractSimpleFusionRuntimeBenchmark.java
+++
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/turtle/runtime/AbstractSimpleFusionRuntimeBenchmark.java
@@ -60,7 +60,6 @@ public abstract class AbstractSimpleFusionRuntimeBenchmark
extends AbstractSimpl
eventSenders.put(eventSender, nrOfEvents);
}
- @Override
protected KieBaseOption[] getKieBaseOptions() {
return new KieBaseOption[]{EventProcessingOption.STREAM};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]