I have a problem with job execution workers.
My example process consists of several asynchronous steps, that takes ~15 seconds to complete each. I’ve made a rest controller that looks like:
@RequestMapping(path = "/create", method = RequestMethod.POST)
public String create() {
runtimeService.startProcessInstanceByKey("example-process");
return "Created";
}
But when i started to assign tasks, all of them run synchronously (i dont use parallel gateway and that’s not my kind of problem).
So, as i think, if i started independent processes of the same type, their job execution should be parallel, why not?
I’m trying to model a payment system, when process consists of several steps, each should be persisted and if an exception occurred, it should restarted from last checkpoint. I’ve done this using asyncbefore service tasks and this problem occurred.
Version:
Spring-Boot: (v1.3.6.RELEASE)
Camunda BPM: (v7.5.0)
Camunda BPM Spring Boot Starter: (v1.2.1)
Mb default taskexecutor pool size is 1?
Hi @Salmondx,
could you attach your process please?
Cheers,
Askar
If i understand you correctly, this is my process diagram:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.2.2">
<bpmn:process id="execute-equation" name="Execute Equation" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1qnzqv5</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1qnzqv5" sourceRef="StartEvent_1" targetRef="Task_0rgp1ol" />
<bpmn:sequenceFlow id="SequenceFlow_1guseov" sourceRef="Task_0rgp1ol" targetRef="Task_0t69dlh" />
<bpmn:businessRuleTask id="Task_0t69dlh" name="Проверка авторизации платежа" camunda:delegateExpression="${operationAuthorization}">
<bpmn:incoming>SequenceFlow_1guseov</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1csn05x</bpmn:outgoing>
</bpmn:businessRuleTask>
<bpmn:serviceTask id="Task_0rgp1ol" name="Получение данных платежа" camunda:delegateExpression="${operationData}">
<bpmn:incoming>SequenceFlow_1qnzqv5</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1guseov</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="SequenceFlow_1csn05x" sourceRef="Task_0t69dlh" targetRef="Task_0k1mwdm" />
<bpmn:serviceTask id="Task_0k1mwdm" name="Проведение проводки" camunda:asyncBefore="true" camunda:delegateExpression="${operationStatus}">
<bpmn:incoming>SequenceFlow_1csn05x</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1lgwbun</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="SequenceFlow_1lgwbun" sourceRef="Task_0k1mwdm" targetRef="Task_1ogz8iz" />
<bpmn:sendTask id="Task_1ogz8iz" name="Отправка смски" camunda:asyncBefore="true" camunda:delegateExpression="${sendSMS}">
<bpmn:incoming>SequenceFlow_1lgwbun</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1ewrr9n</bpmn:outgoing>
</bpmn:sendTask>
<bpmn:endEvent id="EndEvent_0fzutwl">
<bpmn:incoming>SequenceFlow_1ewrr9n</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1ewrr9n" sourceRef="Task_1ogz8iz" targetRef="EndEvent_0fzutwl" />
<bpmn:boundaryEvent id="BoundaryEvent_07qo25q" attachedToRef="Task_0rgp1ol">
<bpmn:errorEventDefinition camunda:errorCodeVariable="WRONG_REFERENCE" camunda:errorMessageVariable="Неправильный референс платежа" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="execute-equation">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="174" y="185" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="147" y="221" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1qnzqv5_di" bpmnElement="SequenceFlow_1qnzqv5">
<di:waypoint xsi:type="dc:Point" x="210" y="203" />
<di:waypoint xsi:type="dc:Point" x="270" y="203" />
<bpmndi:BPMNLabel>
<dc:Bounds x="195" y="178" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_1guseov_di" bpmnElement="SequenceFlow_1guseov">
<di:waypoint xsi:type="dc:Point" x="370" y="203" />
<di:waypoint xsi:type="dc:Point" x="433" y="203" />
<bpmndi:BPMNLabel>
<dc:Bounds x="356.5" y="178" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="BusinessRuleTask_0r1ono9_di" bpmnElement="Task_0t69dlh">
<dc:Bounds x="433" y="163" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_0vs7mg2_di" bpmnElement="Task_0rgp1ol">
<dc:Bounds x="270" y="163" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1csn05x_di" bpmnElement="SequenceFlow_1csn05x">
<di:waypoint xsi:type="dc:Point" x="533" y="203" />
<di:waypoint xsi:type="dc:Point" x="603" y="203" />
<bpmndi:BPMNLabel>
<dc:Bounds x="523" y="178" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ServiceTask_1f50r09_di" bpmnElement="Task_0k1mwdm">
<dc:Bounds x="603" y="163" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1lgwbun_di" bpmnElement="SequenceFlow_1lgwbun">
<di:waypoint xsi:type="dc:Point" x="703" y="203" />
<di:waypoint xsi:type="dc:Point" x="770" y="203" />
<bpmndi:BPMNLabel>
<dc:Bounds x="691.5" y="178" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="SendTask_0cdnhyi_di" bpmnElement="Task_1ogz8iz">
<dc:Bounds x="770" y="163" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0fzutwl_di" bpmnElement="EndEvent_0fzutwl">
<dc:Bounds x="912" y="185" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="885" y="221" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1ewrr9n_di" bpmnElement="SequenceFlow_1ewrr9n">
<di:waypoint xsi:type="dc:Point" x="870" y="203" />
<di:waypoint xsi:type="dc:Point" x="912" y="203" />
<bpmndi:BPMNLabel>
<dc:Bounds x="846" y="178" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="BoundaryEvent_0g3pf49_di" bpmnElement="BoundaryEvent_07qo25q">
<dc:Bounds x="307" y="225" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="280" y="261" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
@Salmondx,
here are initial parameters of default executor in embedded engine
queueSize = 3; corePoolSize = 3; maxPoolSize = 10;
how do you verify that execution happens synchronously?
@aakhmerov
I’ve made synthetical Thread.sleep() in async jobs and watch how they are processed by job scheduler. In my opinion, different jobs should be processed in parallel.
Is there any recommendations to job scheduler worker’s pool size? My process consist’s of large amount of long running jobs.
Hi @Salmondx,
could you implement a unit test to illustrate your problem better? I am not sure I fully understand it. You can use following example as help https://github.com/camunda/camunda-engine-unittest.
About the pool size, there are no specific recommendations it depends on your usecase. You can find detailed documentation on this topic here https://docs.camunda.org/manual/7.5/user-guide/process-engine/the-job-executor/
Hope that helps,
Askar
May be i could try to explain my problem:
I’ve got a several delegates:
@Slf4j
@Component
public class OperationStatus implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
log.info("Test started");
Thread.sleep(4000);
log.info("Test ended");
}
}
And a rest controller:
@Slf4j
@RestController
public class Controller {
@Autowired
private RuntimeService runtimeService;
@RequestMapping(path = "/{reference}/execute", method = RequestMethod.POST)
public String execute(@PathVariable("reference") String reference) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("reference", reference);
runtimeService.startProcessInstanceByKey("execute", parameters);
return "execute started";
}
}
When i post several Http requests, only one background job executes at a time.