# Multi Instance Sub Process takes over and hour to complete after last activity

**URL:** <https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232>\
**Category:** Flowable Engine\
**Created:** [November 20, 2017, 3:08pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232 "2017-11-20T15:08:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_McKinnon](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/robert_mckinnon/32/297_2.png) [@Robert\_McKinnon](https://forum.flowable.org/u/Robert_McKinnon)\
**Post date:** [November 20, 2017, 3:08pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/1 "2017-11-20T15:08:11Z")

</div>

I have process that has a sub process multi-instance. I ran a sample execution that generated 2000 sub processes. The sub process took over an hour to complete after the last activity.

Sample Logs:  
2017-11-20 08:21:05.217 INFO 14498 — [nio-8080-exec-3] log output from last sub process activity  
2017-11-20 09:31:49.512 INFO 14498 — [nio-8080-exec-3] log output from first activity after sub process

Is there a way to make this more efficient or does this lag between the last activity in the sub process and the sub process ending get longer and longer with the number of items in the multi-instance?

---

<div class="post-metadata">

**Author:** ![tijs](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tijs](https://forum.flowable.org/u/tijs)\
**Post date:** [November 22, 2017, 9:35am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/2 "2017-11-22T09:35:46Z")

</div>

Hi,

Really difficult to say without understanding what you are exactly doing in the sub process. I would not expect the Flowable Engine to introduce the lag, so I’m interested in the sub process implementation.

Best regards,

Tijs

---

<div class="post-metadata">

**Author:** ![Robert\_McKinnon](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/robert_mckinnon/32/297_2.png) [@Robert\_McKinnon](https://forum.flowable.org/u/Robert_McKinnon)\
**Post date:** [December 11, 2017, 3:27pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/3 "2017-12-11T15:27:18Z")

</div>

I have since refactored the process to use camel for the sub processing, but initially in the BPMN execution, I had selected 2000 records from a mongoDB and I created a sub process to enrich the data in a sub process.

With 100 records it took about 10 minutes between the last activity and the first activity after the sub process.  
with 2000 it took about hour.  
with 10000, I gave up and killed the process.

My thought is that the data base is in the middle of a transaction processing all of the sub processes and it takes awhile to commit everything coming out of the sub process.

---

<div class="post-metadata">

**Author:** ![veerendrapj1976](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@veerendrapj1976](https://forum.flowable.org/u/veerendrapj1976)\
**Post date:** [March 2, 2021, 5:15am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/4 "2021-03-02T05:15:17Z")

</div>

Hi,  
We have similar issues.

> [@Multiinstance Subprocess Performance degrades as the number of instances increases](https://forum.flowable.org/t/multiinstance-subprocess-performance-degrades-as-the-number-of-instances-increases/7543):
>
> We are using a multi-instance sub process for our ‘for-each’ loop kind of requirement. Please see below sample bpmn for the same. '\> \<process id="SimpleLoopForPerformance" name="SimpleLoopForPerformance" isExecutable="true"\> \<startEvent id="startEvent1" flowable:formFieldValidation="true"\>\</startEvent\> \<serviceTask id="GetRecords1" name="GetRecords1" flowable:delegateExpression="${fetchRecordServiceCall}"\>\</serviceTask\> \<subProcess id="sid-A87F38F2-374D-4E89-889B-938DFB1A4603" name="subPro…

```
   Please let us know if there was any solution / suggestions .

```

Thanks & Regards,  
Veerendra

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [March 9, 2021, 2:07pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/5 "2021-03-09T14:07:28Z")

</div>

Hi Veerendra,

It is hard to guess, but I would expect that there is a problem with transaction commit. If you split your execution into several smaller transaction, problem could be solved.

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![sachindhus](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/sachindhus/32/2296_2.png) [@sachindhus](https://forum.flowable.org/u/sachindhus)\
**Post date:** [March 19, 2021, 4:25am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/6 "2021-03-19T04:25:48Z")

</div>

Hi Martin,

Is there any option to split subprocess transactions into multiple transactions if we will have more than 2000 records in the subprocess?

Or it should commit after N records processed?

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [March 19, 2021, 11:07am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/7 "2021-03-19T11:07:33Z")

</div>

> [@sachindhus](#):
>
> Or it should commit after N records processed?

yes, it is possible.

---

<div class="post-metadata">

**Author:** ![sachindhus](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/sachindhus/32/2296_2.png) [@sachindhus](https://forum.flowable.org/u/sachindhus)\
**Post date:** [March 19, 2021, 11:20am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/8 "2021-03-19T11:20:15Z")

</div>

Thanks, Martin for quick response.

I was going through some of the Flowable properties but unfortunately, I am not able to find any property which can help me to commit the transaction after every N records… Could you please help me if you know any property/configuration to do it?

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [March 23, 2021, 2:54pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/9 "2021-03-23T14:54:58Z")

</div>

> [@sachindhus](#):
>
> commit the transaction after every N records

this is not a configuration property. You have to change your model to allow splitting into several transactions. You can use e.g. multiinstance behavior to achieve it.  
Another possibility is to use batch service (does not have support in activities now)

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![sachindhus](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/sachindhus/32/2296_2.png) [@sachindhus](https://forum.flowable.org/u/sachindhus)\
**Post date:** [March 24, 2021, 6:50pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/10 "2021-03-24T18:50:31Z")

</div>

Thanks Martin.

I am already using multi-instance

`<multiInstanceLoopCharacteristics isSequential="true" flowable:collection="EmployeeRecords"></multiInstanceLoopCharacteristics>`

I think still it is running in the same transaction. Let me check batch service. There are limited docs on batch service.

Regards,  
Sachin

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [March 24, 2021, 7:03pm UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/11 "2021-03-24T19:03:55Z")

</div>

The problem is that you can use `Collection<Collection<Item>>`.  
Outer collection can limit transaction and inner collection contains items processed in one transaction. You have to set async flag to true to start a new transaction for each batch.

another possibility is to use back loop with async flag,

and the third one batch service.

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![sachindhus](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/sachindhus/32/2296_2.png) [@sachindhus](https://forum.flowable.org/u/sachindhus)\
**Post date:** [March 25, 2021, 11:09am UTC](https://forum.flowable.org/t/multi-instance-sub-process-takes-over-and-hour-to-complete-after-last-activity/1232/12 "2021-03-25T11:09:07Z")

</div>

Thanks, Martin for pointing me in the right direction. I will try out all the above options & share the results.

Regards,  
Sachin
