# Fast async job processing at first, slow after

**URL:** <https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620>\
**Category:** Flowable Engine\
**Created:** [July 4, 2024, 2:06pm UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620 "2024-07-04T14:06:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbastov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pbastov/32/2307_2.png) [@pbastov](https://forum.flowable.org/u/pbastov)\
**Post date:** [July 4, 2024, 2:06pm UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/1 "2024-07-04T14:06:01Z")

</div>

Here is our setup:

We run 7 Kubernetes pods with Flowable (v6.4.1) in it configured using these settings (the rest are defaults)

```auto
asyncExecutorThreadPoolQueueSize=200
asyncExecutorCorePoolSize=1
asyncExecutorMaxPoolSize=10
asyncExecutorTimerLockTimeInMillis=600000 (10 minutes)
asyncExecutorAsyncJobLockTimeInMillis=600000 (10 minutes)
asyncExecutorMaxAsyncJobsDuePerAcquisition=5

```

We have a process definition that goes like this: Script Task (async=true) → Exclusive Gateway → Script Task. At the beginning of each month we have to run about 20K of process instances of this process definition.

Because the first Script Task is marked as asynchronous we end up having 20K entries in `act_ru_job`.

When I keep running this query repeatedly `SELECT COUNT(*) FROM act_ru_job` I observe this pattern: the count goes down pretty rapidly for some time, which means the jobs are being processed quite quickly. But then it stalls and takes forever to finish the jobs.

Is it a matter of misconfiguration, e.g. should I adjust some other settings to match the reality? At this point I ran out of ideas. If anyone came across a similar scenario and a similar issue I would appreciate if you could share your experience of solving the issue.

Thank you.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 8, 2024, 6:47am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/2 "2024-07-08T06:47:05Z")

</div>

Hey @pbastov,

I would suggest having the core pool size and max pool size to the same value.

I would also suggest to you to measure the runtime, how many jobs are getting rejected, how fast each job gets executed etc. If everything that is done in the first and second script task is the same speed you should not see a drop in the execution.

You said you are using Flowable 6.4.1, that version is from January 2019, that’s quite old. I would suggest migrating to a newer version, we’ve done numerous improvements around the job execution.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![pbastov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pbastov/32/2307_2.png) [@pbastov](https://forum.flowable.org/u/pbastov)\
**Post date:** [July 8, 2024, 9:12am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/3 "2024-07-08T09:12:20Z")

</div>

Thank you @filiphr. I will try what you suggest…

Indeed, we are still using a pretty old version of the engine.

---

<div class="post-metadata">

**Author:** ![pbastov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pbastov/32/2307_2.png) [@pbastov](https://forum.flowable.org/u/pbastov)\
**Post date:** [July 8, 2024, 9:13am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/4 "2024-07-08T09:13:08Z")

</div>

Btw, @filiphr any advice on how to “measure the runtime”? Are there tools built into Flowable to do that?

---

<div class="post-metadata">

**Author:** ![pbastov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pbastov/32/2307_2.png) [@pbastov](https://forum.flowable.org/u/pbastov)\
**Post date:** [July 8, 2024, 9:24am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/5 "2024-07-08T09:24:24Z")

</div>

And another question, @filiphr: there is this parameter called `asyncExecutorDefaultQueueSizeFullWaitTime` that is described as follows:

> The time (in milliseconds) the async job (both timer and async continuations) acquisition thread will wait when the internal job queue is full to execute the next query. By default set to 0 (for backwards compatibility). Setting this property to a higher value allows the async executor to hopefully clear its queue a bit.

Does it help, in general, to speed things up if I set it to a non-zero value, e.g. 10000 (10 seconds)?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [July 8, 2024, 9:42am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/6 "2024-07-08T09:42:01Z")

</div>

> [@pbastov](#):
>
> Btw, @filiphr any advice on how to “measure the runtime”? Are there tools built into Flowable to do that?

In the open source we don’t really have something out-of-the-box. We do have different listeners that you could hook into in theory and measure it.

> [@pbastov](#):
>
> Does it help, in general, to speed things up if I set it to a non-zero value, e.g. 10000 (10 seconds)?

Now that you mention this, I see that you also have the `asyncExecutorMaxAsyncJobsDuePerAcquisition` set to `5`. This means that there is a lot of contention by the different nodes. The nodes keep trying to get the same jobs and lock them. We’ve done a lot of improvements in this area in 6.7.

I would suggest that you read the following blog serios:

- [Handling asynchronous operations with Flowable – Part 1: Introducing the new Async Executor](https://www.flowable.com/blog/engineering/handling-asynchronous-operations-with-flowable-part-1-introducing-the-new-async-executor)
- [Handling Asynchronous Operations with Flowable – Part 2: Components & Configuration](https://www.flowable.com/blog/engineering/handling-asynchronous-operations-with-flowable-part-2-components-configuration)
- [Handling Asynchronous Operations with Flowable – Part 3: Performance Benchmarks](https://www.flowable.com/blog/engineering/handling-asynchronous-operations-with-flowable-part-3-performance-benchmarks)
- [Handling Asynchronous Operations with Flowable – Part 4: Evolution of the Async Executor](https://www.flowable.com/blog/engineering/handling-asynchronous-operations-with-flowable-part-4-evolution-of-the-async-executor)

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![pbastov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pbastov/32/2307_2.png) [@pbastov](https://forum.flowable.org/u/pbastov)\
**Post date:** [July 8, 2024, 9:57am UTC](https://forum.flowable.org/t/fast-async-job-processing-at-first-slow-after/11620/7 "2024-07-08T09:57:41Z")

</div>

Thank you for your reply and for the links. I believe I came across them and read, but I will give them another read.
