4

I have a simple question on using the fork join thread pool. Here is a short example of what I'm using:

  executor = "fork-join-executor"
  # Configuration for the fork join pool
  fork-join-executor {
    # Min number of threads to cap factor-based parallelism number to
    parallelism-min = 24
    # Parallelism (threads) ... ceil(available processors * factor)
    parallelism-factor = 4.0
    # Max number of threads to cap factor-based parallelism number to
    parallelism-max = 48
  }

What I'm not sure is that, how many threads will be created in this case? I'm running on a 2 core machine, so it is 24 threads per core with a max of 48 threads?

With the parallelism factor set to 4.0, the number of threads that can be run in parallel is going to be 8. So what is the need for setting the min and max values which is my case is 24 and 48?

Mifeet
  • 10,908
  • 3
  • 50
  • 92
joesan
  • 10,737
  • 20
  • 70
  • 176

1 Answers1

6

Let's start by explaining how parallelism in ForkJoinPool works. The number of threads is controlled by a single (constructor) parameter parallelism (the number of cores by default). ForkJoinPool tries to keep at most parallelism running threads. But it can decide to spawn more threads, if some of them are blocked. E.g. If you have too many forked tasks that are waiting for join, your computation would be blocked unless you add new threads; the waiting threads are active but not running (because they wait). More explanation here.

The dispatcher configuration in your questions controls what value the parallelism parameter will be set to. It is set to available processors * parallelism-factor but at least parallelism-min and at most parallelism-max. See more info here and here.

How many threads will be created in this case?

The parallelism should be 2 cores * 4 -> 8 threads. So the number of running threads should be 8, but the number of created threads in total may be higher.

What is the need for setting the min and max values which is my case is 24 and 48

I think it's only in case you deployed on a machine with a different number of cores.

Mifeet
  • 10,908
  • 3
  • 50
  • 92
  • Parallelism is capped by parallelism-max and parallelism-min. essentially the result of max(parallelism-min, min(parallelism-max, cores * parallelism-factor)) . – Viswa Teja Kuncham Aug 29 '20 at 12:02