1

I have a calculation heavy spring boot application that runs on an AWS t3.large EC2 instance, with 2 virtual CPUs.

I have two steps in the calculation and for the first step, I intend to use supplyAsync with a thread pool of 2 threads because of the 2vcpus.

The second step involves a fork join (happens after step 1 is completed). However, with this, if I use the commonPool, which I can because it is only doing calculations, that would mean it runs on parallelism = 1. This means JVM will create a thread for each task (reference : https://dzone.com/articles/be-aware-of-forkjoinpoolcommonpool). I am anticipating the sub tasks to be over 10. Therefore creating 10 or more threads feels like an overkill due to the memory it consumes.

Does it make sense to use the fork join approach if I only have 2 vcpus?

maheeka
  • 1,983
  • 1
  • 17
  • 25
  • Just create a ForkJoin pool with your own ThreadPool having # of CPUs threads. – oneat May 31 '21 at 23:34
  • you might want to read [this](https://stackoverflow.com/a/65768653/1059372). parallelism might very well not be `1`. "Therefore creating 10 or more threads feels like an overkill due to the memory it consumes" - is at least a bit incorrect too. thread stacks are populated in a lazy fashion, and usually are rather small. Overall, I find your question confusing. – Eugene Jun 01 '21 at 02:15
  • Curious when you say "...feels like an overkill due to the memory it consumes.", are you referring to the memory an additional thread would consume? Or are you suggesting the sub-task itself is large and therefore you expect it to consume a lot of memory in the process of computing its result? – Atmas Jun 01 '21 at 15:55
  • 2
    it would be rather helpful if you would come back with some of the answers to the comments, otherwise I doubt someone will be able to help you – Eugene Jun 03 '21 at 02:45

0 Answers0