# Multi-instance optimization (parallel execution)

**URL:** <https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [September 6, 2018, 11:51am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825 "2018-09-06T11:51:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 6, 2018, 11:51am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/1 "2018-09-06T11:51:58Z")

</div>

Hello there.

I have call activity element (multi-instance) that I’m trying to execute in parallel. I have 30 000 instances that I need to run. For now, it’s too slow. It takes about 3 hours to finish with the starting all process instances.

On my call activity I’ve set the following properties:  
**Collection** : ${productList}  
**ElementVariable** : product

**Multi Instance Asynchronous Before** : checked  
**Multi Instance Asynchronous After** : not checked  
**Multi Instance Exclusive** : checked

**_Asynchronous Continuation_**

- Asynchronous Before: checked
- Asynchronous After: not checked
- Exclusive: not checked

**_NOTE_** : Inside call activity I check target days and on each day I’m calling different activity (new call activity element - sub process).

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 7, 2018, 7:12am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/2 "2018-09-07T07:12:42Z")

</div>

Does anyone knows anything about this?

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [September 10, 2018, 6:41am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/3 "2018-09-10T06:41:43Z")

</div>

You should consider changing the settings of the [Job Executor](https://docs.camunda.org/manual/7.9/reference/deployment-descriptors/tags/job-executor/) in order increase the number of jobs that can be done.  
I’m not sure if you’re using a cluster or not, but if you’re only using a single node you should[start up a few nodes](https://docs.camunda.org/manual/7.9/user-guide/process-engine/the-job-executor/#cluster-setups) to help with processing.

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 10, 2018, 6:51am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/4 "2018-09-10T06:51:11Z")

</div>

Hi @Niall, thank you for your answer. I’m using a single node. I will try to run in cluster.

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 13, 2018, 5:22pm UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/5 "2018-09-13T17:22:54Z")

</div>

@Niall is there any other way to speed up the processes?  
Here is my job-executor configuration:

job-execution:  
core-pool-size: 10  
max-jobs-per-acquisition: 10  
max-pool-size: 10  
queue-capacity: 10

and I’m using audit history level.

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [September 14, 2018, 5:54am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/6 "2018-09-14T05:54:18Z")

</div>

What exactly are you trying to achieve - are you specifically testing performance or do you have this specific load in a production system?

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 14, 2018, 6:31am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/7 "2018-09-14T06:31:46Z")

</div>

@Niall I have this specific load in production. It’s too slow for now… I’m running ~30 000 process instances every morning. It takes about 3h to finish but I only have 40 minutes to finish with all processes.

I’m using MySQL, Spring Boot and Centos7 server with 16GB RAM and 2 CPUs.

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [September 14, 2018, 9:27am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/8 "2018-09-14T09:27:44Z")

</div>

It’s not entirely clear exactly what is is that is causing the delay, it could be the delegate code, it could be slow network calls. The engine itself shouldn’t have too much trough with that load so i’m not sure if the engine itself is the bottle neck.

Either way have you tried adding more nodes? Creating a cluster?

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 14, 2018, 10:22am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/9 "2018-09-14T10:22:33Z")

</div>

Here is the part of main process:  
 ![main-process-part](https://forum.camunda.io/uploads/default/original/2X/d/db6941cdfa4e8f28ec6f01564a58c3653615cf01.png)

In this call activity I pass about 30 000 instances (products). Then the following BPMN is called for each instance.

 ![instance-part](https://forum.camunda.io/uploads/default/original/2X/0/07c39669a3b76d9be8f460f48a95455e484ffcf5.png)

For now I don’t have possibility to add more nodes. I’m limited to single node. I can only increase number of cores to 8 and RAM to 32GB.

The product variable is about 8KB.

---

<div class="post-metadata">

**Author:** ![tiesebarrell](https://forum.camunda.io/user_avatar/forum.camunda.io/tiesebarrell/32/4301_2.png) [@tiesebarrell](https://forum.camunda.io/u/tiesebarrell)\
**Post date:** [September 14, 2018, 10:57am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/10 "2018-09-14T10:57:04Z")

</div>

The conditions for the conditional start events of the event subprocesses will be evaluated immediately when starting the process IIRC. If checking those conditions is processing intensive, that might be an issue because there are three at the root level.

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 14, 2018, 11:29am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/11 "2018-09-14T11:29:03Z")

</div>

@tiesebarrell those conditions only checks the properties of passed instance (product). For example condition is: product.getDueDays() == 3 && product.getProductCatalogType() == ‘loan’

Also, there is about 20 sub-processes with conditions. On image are only three because is the only one part of process screenshot.

---

<div class="post-metadata">

**Author:** ![tiesebarrell](https://forum.camunda.io/user_avatar/forum.camunda.io/tiesebarrell/32/4301_2.png) [@tiesebarrell](https://forum.camunda.io/u/tiesebarrell)\
**Post date:** [September 14, 2018, 11:58am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/12 "2018-09-14T11:58:05Z")

</div>

OK, then it’s unlikely that they take up so much time. For the ones that get started, those 20 (!) conditions will be re-evaluated with variable updates. So if you’re updating variables a lot, there’s a lot of work going on there potentially, if you didn’t specify and restrict which variable updates should be used.

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [September 14, 2018, 12:16pm UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/13 "2018-09-14T12:16:19Z")

</div>

@tiesebarrell So, is it a better idea to put those conditions, maybe in DMN, or in service delegate? What you suggest?

---

<div class="post-metadata">

**Author:** ![tiesebarrell](https://forum.camunda.io/user_avatar/forum.camunda.io/tiesebarrell/32/4301_2.png) [@tiesebarrell](https://forum.camunda.io/u/tiesebarrell)\
**Post date:** [September 14, 2018, 1:24pm UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/14 "2018-09-14T13:24:37Z")

</div>

There’s no easy way of saying in a generic way, because it depends massively on the functional goals for the process. If those conditions are only relevant at a certain point in the process, then a decision at that point in the process makes more sense. But if the process is truly monitoring 20 conditions all at once all the time, then what you have is possibly correct. It seems like an uncommon case though. You could also actively trigger re-evaluation of the conditions in a single event subprocess with a message start event, or check them from time to time in one with a timer start event. At least then you could bundle a lot of them.

Again, it depends very much on the functional requirements. But looking back at your original question, first step would be t determine if the evaluation of the conditions is actually slowing stuff down. You could experiment with a test where you strip them all from the process and start the same number of instances. If that makes a big difference, that’s your pointer to look at the conditions.

---

<div class="post-metadata">

**Author:** ![Cosmin](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@Cosmin](https://forum.camunda.io/u/Cosmin)\
**Post date:** [June 21, 2019, 10:46am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/15 "2019-06-21T10:46:21Z")

</div>

Hey @heril.muratovic06

Did you found any solutions?

From my tests I saw that the larger the collection the more time it takes to initialize the multi instance.  
It seems that the collection is passed to each instance.  
So if you have 30k values then you have 30k instances with a collection of 30k elements.

I wonder if there is the possibility to avoid passing the collection along.

Best regards,  
Cosmin

---

<div class="post-metadata">

**Author:** ![heril.muratovic06](https://forum.camunda.io/user_avatar/forum.camunda.io/heril.muratovic06/32/32461_2.png) [@heril.muratovic06](https://forum.camunda.io/u/heril.muratovic06)\
**Post date:** [June 24, 2019, 6:17am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/16 "2019-06-24T06:17:33Z")

</div>

Hi @Cosmin,

I have removed all those conditions from BPMN and make one service task in which I’m using java parallel stream to start processes manually (with runtime service).  
Also, I have implemented custom history level to reduce number of queries. It seems faster but not too much.

For those 30k instances execution time is about 1 hour which is generally slow.

---

<div class="post-metadata">

**Author:** ![Cosmin](https://forum.camunda.io/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@Cosmin](https://forum.camunda.io/u/Cosmin)\
**Post date:** [July 9, 2019, 1:01pm UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/17 "2019-07-09T13:01:35Z")

</div>

Hey @heril.muratovic06,

My solution was to split the collection.  
Now I have 20-30 multi instance activities with 500-1000 entities.

The process seems to move a lot faster in my case.

---

<div class="post-metadata">

**Author:** ![IdemenB](https://forum.camunda.io/user_avatar/forum.camunda.io/idemenb/32/9635_2.png) [@IdemenB](https://forum.camunda.io/u/IdemenB)\
**Post date:** [April 17, 2021, 4:50pm UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/18 "2021-04-17T16:50:09Z")

</div>

Hi Cosmin, are you sure about this? As far as I observe, only the particular item in the collection is repeated per each instance, not the whole collection.

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 11:22am UTC](https://forum.camunda.io/t/multi-instance-optimization-parallel-execution/8825/19 "2024-01-30T11:22:16Z")

</div>

Closed on January 30, 2024, 11:22am UTC


