Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROOLS-7573 - add parameter for h2vm/infinispan store #268

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,6 +44,7 @@
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 {

Expand All @@ -62,9 +66,19 @@ public String getInfinispanStorageMode() {
}
}

public enum Module {
INFINISPAN,
H2MVSTORE
}
Comment on lines +71 to +74
Copy link
Contributor

@tkobayas tkobayas Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I thought that Module is a good idea. But then we have to deal with unexpected combinations like "H2MVSTORE" + "REMOTE", or "H2MVSTORE" + "REMOTEPROTO".

If you run

java -jar target/drools-benchmarks-reliability.jar -jvmArgs "-Xms4g -Xmx4g" -foe true -wi 0 -i 1 -f 1 org.drools.benchmarks.reliability.InsertAndFireBenchmark

You will hit a failure with such a combination.

Probably it's better to use only Mode as a benchmark parameter. You may still use Module for internal code writing convenience (for example, Mode can have Module). So add "H2MVSTORE" to Mode. Maybe also it's better to rename like "EMBEDDED" to "INFINISPAN_EMBEDDED" and so on (but infinispanStorageMode values shouldn't be changed , because it's used for INFINISPAN_STORAGE_MODE)

Let me know if it's not clear for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I understand. I will make the changes needed.


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

@Param({"NONE", "EMBEDDED", "REMOTE", "REMOTEPROTO"})
protected Mode mode;

@Param({"INFINISPAN", "H2MVSTORE"})
protected Module module;

@Param({"true", "false"})
protected boolean useSafepoints;

Expand All @@ -74,25 +88,33 @@ public String getInfinispanStorageMode() {
public void setupEnvironment() {
FileUtils.deleteDirectory(Path.of(GLOBAL_STATE_DIR));

if (mode != NONE) {
System.setProperty(INFINISPAN_STORAGE_MODE, mode.getInfinispanStorageMode());
}
if (module == Module.H2MVSTORE){
H2MVStoreStorageManager.cleanUpDatabase();
System.setProperty(DROOLS_RELIABILITY_MODULE_TEST, "H2MVSTORE");
configureServicePriorities();
}else { // assuming infinispan is the default module
System.setProperty(DROOLS_RELIABILITY_MODULE_TEST, "INFINISPAN");
configureServicePriorities();
Copy link
Contributor

@tkobayas tkobayas Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this configureServicePriorities(); (for infinispan) to line-110. `configureServicePriorities() triggers storage initialization, so it should be called after all system properties are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

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 == EMBEDDED || mode == REMOTE) {
System.setProperty(INFINISPAN_STORAGE_ALLOWED_PACKAGES, "org.drools.benchmarks.common.model");
}

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

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 == REMOTE || mode == REMOTEPROTO) {
container = new InfinispanContainer();
container.start();
InfinispanStorageManager storageManager = (InfinispanStorageManager) StorageManagerFactory.get().getStorageManager();
RemoteCacheManager remoteCacheManager = container.getRemoteCacheManager(storageManager.provideAdditionalRemoteConfigurationBuilder());
storageManager.setRemoteCacheManager(remoteCacheManager);
}
}
}

Expand Down Expand Up @@ -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 @@ -46,6 +46,9 @@ public class InsertFailoverFireBenchmark extends AbstractReliabilityBenchmarkFai
@Param({"EMBEDDED"})
private Mode mode;

@Param({"INFINISPAN", "H2MVSTORE"})
protected Module module;

@Param({"true", "false"})
private boolean useObjectStoreWithReferences;

Expand All @@ -63,7 +66,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 @@ -103,25 +106,29 @@ protected void populateKieSessionPerIteration() {
@Benchmark
public long test() {
kieSession = restoreSession();
//System.out.println("restored : facts size = " + kieSession.getFactHandles().size());
// 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.module = Module.H2MVSTORE;
benchmark.mode = Mode.EMBEDDED;
benchmark.useObjectStoreWithReferences = true;
benchmark.useSafepoints = true;

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

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

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