-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROOLS-7543 : benchmark to test session restore after failover (#266)
* InsertFailoverFireBenchmark * PR comments
- Loading branch information
Showing
6 changed files
with
216 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n/java/org/drools/benchmarks/reliability/AbstractReliabilityBenchmarkFailoverSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...iability/src/main/java/org/drools/benchmarks/reliability/InsertFailoverFireBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters