Skip to content

Commit

Permalink
With the hard-coded benchmark for alphasupport.dmn (apache#10)
Browse files Browse the repository at this point in the history
* With the hard-coded benchmark for alphasupport.dmn

* update 2019 09 30 not working
  • Loading branch information
tarilabs authored and lucamolteni committed Jan 28, 2021
1 parent a221149 commit 4a7db55
Show file tree
Hide file tree
Showing 8 changed files with 5,105 additions and 12 deletions.
47 changes: 46 additions & 1 deletion kie-dmn/kie-dmn-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-api</artifactId>
Expand Down Expand Up @@ -193,7 +203,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down Expand Up @@ -260,4 +270,39 @@
</testResource>
</testResources>
</build>
<profiles>
<profile>
<id>alphasupport</id>
<activation>
<property><name>alphasupport</name></property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>drools-benchmarks</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/kie.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2019 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.kie.dmn.core.alphasupport;

import java.math.BigDecimal;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.DMNRuntime;
import org.kie.dmn.core.util.KieHelper;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.slf4j.Logger;

@BenchmarkMode(Mode.SingleShotTime)
@State(Scope.Thread)
@Warmup(iterations = 100)
@Measurement(iterations = 50)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class DMNDecisionTableAlphaSupportingDraftBench {

private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(DMNDecisionTableAlphaSupportingDraftBench.class);
private DMNRuntime runtime;
private DMNModel dmnModel;
private String existingCustomer;
private BigDecimal score;

@Setup()
public void init() {
final KieServices ks = KieServices.Factory.get();
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"),
ks.getResources().newClassPathResource("alphasupport.dmn", DMNDecisionTableAlphaSupportingDraftBench.class));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_c0cf6e20-0b43-43ce-9def-c759a5f86df2", "DMN Specification Chapter 11 Example Reduced");
}

@Setup(Level.Iteration)
public void initIterationValues() {
this.existingCustomer = existingCustomer();
this.score = new BigDecimal(Double.valueOf((Math.random() * (140 - 70)) + 70).intValue());
}

public String existingCustomer() {
char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
int randomIdx = new Random().nextInt(alphabet.length + 2);
if (randomIdx < alphabet.length - 2) {
return String.valueOf(alphabet[randomIdx]);
} else {
return (randomIdx - 2) == 0 ? "true" : "false";
}
}

@Benchmark
public DMNResult doTest() {
final DMNContext context = runtime.newContext();
context.set("Existing Customer", existingCustomer);
context.set("Application Risk Score", score);
DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", evaluateAll);
return evaluateAll;
}

public void testSimpleDecision() {
final DMNResult dmnResult = doTest();
LOG.debug("{}", dmnResult);
}

public static void main(String[] args) {
DMNDecisionTableAlphaSupportingDraftBench u = new DMNDecisionTableAlphaSupportingDraftBench();
u.init();
u.initIterationValues();
u.doTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public static CompiledAlphaNetwork generateCompiledNetwork() {
AlphaNode alphac2r8 = createAlphaNode(ctx, alphac1r5, x -> UT10.apply(x, x.getValue("Application Risk Score")));
addResultSink(ctx, network, alphac2r8, "LOW");

char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
for (char c : alphabet) {
alphabet(network, ctx, String.valueOf(c));
}

Index index3 = createIndex(String.class, x -> (String)x.getValue("Existing Customer"), "dummy");
AlphaNode alphaDummy = createAlphaNode(ctx, ctx.otn, x -> false, index3);
addResultSink(ctx, network, alphaDummy, "DUMMY");
Expand All @@ -151,6 +156,22 @@ public static CompiledAlphaNetwork generateCompiledNetwork() {
return network;
}

private static void alphabet(CompiledAlphaNetwork network, NetworkBuilderContext ctx, String sChar) {
System.out.println(sChar);
final org.kie.dmn.feel.runtime.UnaryTest UTx = (feelExprCtx, left) -> gracefulEq(feelExprCtx, sChar, left);
Index index1 = createIndex(String.class, x -> (String) x.getValue("Existing Customer"), sChar);
AlphaNode alphac1r1 = createAlphaNode(ctx, ctx.otn, x -> UTx.apply(x, x.getValue("Existing Customer")), index1);

AlphaNode alphac2r1 = createAlphaNode(ctx, alphac1r1, x -> UT2.apply(x, x.getValue("Application Risk Score")));
addResultSink(ctx, network, alphac2r1, "HIGH");
AlphaNode alphac2r2 = createAlphaNode(ctx, alphac1r1, x -> UT3.apply(x, x.getValue("Application Risk Score")));
addResultSink(ctx, network, alphac2r2, "MEDIUM");
AlphaNode alphac2r3 = createAlphaNode(ctx, alphac1r1, x -> UT4.apply(x, x.getValue("Application Risk Score")));
addResultSink(ctx, network, alphac2r3, "LOW");
AlphaNode alphac2r4 = createAlphaNode(ctx, alphac1r1, x -> UT5.apply(x, x.getValue("Application Risk Score")));
addResultSink(ctx, network, alphac2r4, "VERY LOW");
}

private static void addResultSink( NetworkBuilderContext ctx, CompiledAlphaNetwork network, ObjectSource source, Object result ) {
source.addObjectSink( new ResultCollectorAlphaSink( ctx.buildContext.getNextId(), source, ctx.buildContext, result, network.resultCollector ) );
}
Expand Down
35 changes: 35 additions & 0 deletions kie-dmn/kie-dmn-core/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016 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.
-->

<configuration>

<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%method:%line - %msg%n</pattern>
</encoder>
</appender>

<logger name="org.kie" level="debug"/>
<logger name="org.drools.compiler.reteoo.compiled" level="debug"/>
<logger name="org.kie.dmn.core.compiler.execmodelbased" level="info"/> <!-- useful default when moving generic org.kie to <info -->
<logger name="org.kie.dmn.feel.codegen" level="info"/> <!-- useful default when moving generic org.kie to <info -->

<root level="warn">
<appender-ref ref="consoleAppender" />
</root>

</configuration>
Loading

0 comments on commit 4a7db55

Please sign in to comment.