100% cpu on REST call to rules engine from Java API

578 views
Skip to first unread message

Johan Wasserman

unread,
Mar 4, 2017, 9:52:04 PM3/4/17
to Drools Usage
I have seen at least 3 other unanswered posts on this topic.  Does anyone make successful java API calls to the REST interface, and if so, could you please help me figure this out?  Pretty please?

When making the REST call, the CPU spikes and just stays there.

$ top
  PID  USER               PR  NI    VIRT      RES       SHR S  %CPU  %MEM     TIME+     COMMAND
 4174 [processowner]   20   0     8179888 2.381g  28148 S    757.5  7.6            226:07.48 java

$ ps -ef | 4174
[processowner]   4174  4081 99 08:35 ?        03:46:48 /usr/lib/jvm/java/bin/java -D[Standalone] -server -Xms256m -Xmx2048m -Dorg.optaplanner.server.ext.disabled=true -Dorg.jbpm.server.ext.disabled=true -Dorg.jboss.boot.log.file=/opt/jboss/wildfly/standalone/log/server.log -Dlogging.configuration=file:/opt/jboss/wildfly/standalone/configuration/logging.properties -jar /opt/jboss/wildfly/jboss-modules.jar -mp /opt/jboss/wildfly/modules org.jboss.as.standalone -Djboss.home.dir=/opt/jboss/wildfly -Djboss.server.base.dir=/opt/jboss/wildfly/standalone -b 0.0.0.0 -Dorg.kie.server.id=kie-server-9cd4212cbdcb -Dorg.kie.server.user=kieserver -Dorg.kie.server.pwd=xxxxxxxxxx -Dorg.kie.server.location=http://172.17.0.3:8080/kie-server/services/rest/server -Dorg.kie.server.controller=http://172.17.0.2:8080/drools-wb/rest/controller -Dorg.kie.server.controller.user=admin -Dorg.kie.server.controller.pwd=xxxxxxxxxxx -c standalone-full-kie-server.xml

I'm running the Docker images: jboss/drools-workbench-showcase  and  jboss/kie-server-showcase  with optaplanner and jbpm disabled.

Screenshot, Code and Output below.

String USR = "kieserver";
String PWD = "xxxxxxxxxx";
String CONTAINER = "Relationship";

KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(URL, USR, PWD);

Set<Class<?>> allClasses = new HashSet<Class<?>>();
allClasses.add(Relationship.class);
allClasses.add(org.drools.core.command.runtime.rule.FireAllRulesCommand.class);
allClasses.add(org.drools.core.command.runtime.rule.InsertObjectCommand.class);
allClasses.add(org.drools.core.common.DefaultFactHandle.class);
allClasses.add(org.drools.core.command.runtime.rule.GetObjectCommand.class);
config.addExtraClasses(allClasses);

KieServicesClient client = KieServicesFactory.newKieServicesClient(config);

RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);

List<GenericCommand<?>> commands = new ArrayList<GenericCommand<?>>();

Relationship rel = new Relationship();
rel.setSource_class("Server Hosting");
rel.setTarget_class("Virtual Host");
rel.setSource_option1("Provisioning");

System.out.println("===output====");
System.out.println(rel.toString());
KieCommands cmdFactory = KieServices.Factory.get().getCommands();

commands.add((GenericCommand<?>) cmdFactory.newInsert(rel, "insert-identifier"));
commands.add((GenericCommand<?>) cmdFactory.newFireAllRules("fire-identifier"));
BatchExecutionCommand command = cmdFactory.newBatchExecution(commands, "defaultKieSession");

Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.XSTREAM, temp.class.getClassLoader());

String out = marshaller.marshall(command);
System.out.println(out);

Marshaller marshallerJson = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, temp.class.getClassLoader());
String outJson = marshallerJson.marshall(command);
System.out.println("\n\n" + outJson);

System.out.println("===server response====");

ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER, command);
System.out.println(response.getResult());

===output====

com.services.configuration.Relationship@44f75083
<batch-execution lookup="defaultKieSession">
  <insert out-identifier="insert-identifier" return-object="true" entry-point="DEFAULT">
    <com.services.configuration.Relationship>
      <source__class>Server Hosting</source__class>
      <source__option1>Provisioning</source__option1>
      <target__class>Virtual Host</target__class>
      <impact>false</impact>
    </com.services.configuration.Relationship>
  </insert>
  <fire-all-rules out-identifier="fire-identifier"/>
</batch-execution>


{
  "lookup" : "defaultKieSession",
  "commands" : [ {
    "insert" : {
      "object" : {"com.services.configuration.Relationship":{
  "source_class" : "Server Hosting",
  "source_option1" : "Provisioning",
  "source_option2" : null,
  "source_option3" : null,
  "target_class" : "Virtual Host",
  "target_option1" : null,
  "target_option2" : null,
  "target_option3" : null,
  "impact_model" : null
}},
      "disconnected" : false,
      "out-identifier" : "insert-identifier",
      "return-object" : true,
      "entry-point" : "DEFAULT"
    }
  }, {
    "fire-all-rules" : {
      "max" : -1,
      "out-identifier" : "fire-identifier"
    }
  } ]
}
===server response====
Exception in thread "main" org.kie.remote.common.rest.KieRemoteHttpRequestException: Error occurred when trying to retrieve response code
at org.kie.remote.common.rest.KieRemoteHttpRequest.responseCode(KieRemoteHttpRequest.java:1331)
at org.kie.remote.common.rest.KieRemoteHttpRequest.post(KieRemoteHttpRequest.java:719)
at org.kie.server.client.impl.AbstractKieServicesClientImpl.makeHttpPostRequestAndCreateServiceResponse(AbstractKieServicesClientImpl.java:244)
at org.kie.server.client.impl.AbstractKieServicesClientImpl.makeHttpPostRequestAndCreateServiceResponse(AbstractKieServicesClientImpl.java:234)
at org.kie.server.client.impl.RuleServicesClientImpl.executeCommandsWithResults(RuleServicesClientImpl.java:72)
at temp.try2(temp.java:65)
at temp.main(temp.java:19)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at org.kie.remote.common.rest.KieRemoteHttpRequest.responseCode(KieRemoteHttpRequest.java:1329)
... 6 more

I've spent two days trying this every which way and I would very much appreciate some help.

Thanks,
J.

laphroaig15

unread,
Mar 5, 2017, 1:10:28 AM3/5/17
to drools...@googlegroups.com, Johan Wasserman
Have you ruled out an assertion storm and high GC overhead due to heap exhaustion?
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Johan Wasserman

unread,
Mar 5, 2017, 1:20:17 AM3/5/17
to Drools Usage, johan.w...@gmail.com
I may just be naive but all that I have on the server is one small data object and two very simple rules... It's pretty much a fresh install that I'm planing to do a POC on, if I can get it to work.

laphroaig15

unread,
Mar 5, 2017, 1:23:42 AM3/5/17
to drools...@googlegroups.com, Johan Wasserman, johan.w...@gmail.com
It only takes one rule to create a loop, but it was worth a shot. :)

Johan Wasserman

unread,
Mar 5, 2017, 1:24:08 AM3/5/17
to Drools Usage, johan.w...@gmail.com
Also, nothing in the logs...  

laphroaig15

unread,
Mar 5, 2017, 1:44:21 AM3/5/17
to drools...@googlegroups.com, Johan Wasserman, johan.w...@gmail.com
I'm running embedded, so no execution engine. Presumably, there's some way to enable the debug listeners to log agenda and working memory. Worst case kill -3 to grab a couple of heap dumps and see where it's stuck.

Johan Wasserman

unread,
Mar 5, 2017, 5:46:33 PM3/5/17
to Drools Usage, johan.w...@gmail.com
Ok, I trashed the docker containers, again, and restarted from scratch making particularly sure I avoid any possible looping by excessive use of "no-loop", this time everything worked.

Thanks for your help Googleis... 

skumari

unread,
Mar 6, 2017, 12:35:34 PM3/6/17
to Drools Usage
Hi Johan,

I was trying to run your client program and not able to import RuleServicesClient by adding below dependency. I am wondering what version of kie-server-client are you using ?
    <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-server-client</artifactId>
            <version>6.2.0.Final</version>
        </dependency>

Your reply is appreciated.

Johan Wasserman

unread,
Mar 7, 2017, 12:57:34 AM3/7/17
to Drools Usage

Johan Wasserman

unread,
Mar 7, 2017, 2:15:49 AM3/7/17
to Drools Usage


On Tuesday, March 7, 2017 at 4:35:34 AM UTC+11, skumari wrote:

skumari

unread,
Mar 7, 2017, 11:06:13 AM3/7/17
to Drools Usage
Thank you Johan.
Reply all
Reply to author
Forward
0 new messages