3

While a java application server will extend a unique JVM to run several (micro)services, a dockerized java microservices architecture will run a JVM for each dockerized microservice. Considering 20+ java microservices and a limited number of host it seems that the amount of resources consumed by the JVMs on each host is huge.

Is there an efficient way to manage this problem ? Is it possible to tune each JVM to limit resources consumption ? The aim is to limit the overhead of using docker in a java microservices architecture.

DouglasAdams
  • 490
  • 7
  • 19

1 Answers1

3

Each Docker and JVM copy running uses memory. Normally having multiple JVMs on a single node would use shared memory, but this isn't an option with docker.

What you can do is reduce the maximum heap size of each JVM. However, I would allow at least 1 GB per docker image as overhead plus your heap size for each JVM. While that sounds like a lot of memory it doesn't cost so much these days.

Say you give each JVM a 2 GB heap and add 1 GB for docker+JVM, you are looking needing a 64 GB server to run 20 JVMs/dockers.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Thanks for the answer. Where can I find some 'casual' values for the JVM stack ? Actually, 500MB seems largely enough for my µS (even in charge). (I check it with jvisualv). So I am impressed by the values ​​that you recommend . – DouglasAdams Sep 09 '16 at 09:58
  • @DouglasAdams some of our clients have JVM with 100 TB virtual memory sizes. If you have 0.5 GB heap per JVM you will find you need quite a bit more in over head. – Peter Lawrey Sep 09 '16 at 10:11
  • @DouglasAdams what do you mean by values for the JVM stack? Do you mean what are the defaults? If you have a small number of threads it shouldn't need tuning. – Peter Lawrey Sep 09 '16 at 10:12
  • Our µS are generally single threaded and not very greedy (no complex calculus). In this case, do you recommend to reduce the value of the heap? Or is it better to leave the default values? – DouglasAdams Sep 12 '16 at 11:36
  • @DouglasAdams If each JVM is in it's own Docker, it will use 1/4 of the memory given to each Docker by default. The JVM is tuned assuming it's not the only application on the machine. Most likely you will want to set the maximum heap size to be all the available memory after the OS and memory needed to run the JVM. – Peter Lawrey Sep 12 '16 at 12:09
  • @DouglasAdams once your services become more stable you might find that combining services into the same JVM or docker is more efficient from a management and CPU/memory performance perspective. This way you might find the number of docker images is about 1-3x the number of developers you have even as you develop more and more services over time. – Peter Lawrey Sep 12 '16 at 12:12