Java Application Theme Number and Performance

Hi: I have a multi-threaded Java application. The current thread size is already 100. We currently use 4 main CPUs. But, as can be seen in the near future, the processor core will be doubled or even up to 32 cores. To fully utilize the cores, we need to increase the thread pool size. But, as you know (maybe I'm wrong), Java is good when there are 100 hundred threads, but a performance problem can occur with a thread of 200, 500, 1000 threads. Then we will use another programming language, for example scala. Is my concern reasonable to me?

+6
source share
4 answers

Using modern JVMs, the Java process can create as many threads as the operating system allows. Regardless of whether your application can use these streams effectively, it depends on the design of your application.

If scalability is a problem, I would recommend focusing primarily on the architecture of your application (data structures, synchronization, etc.). These problems must be considered regardless of the programming language, and there is nothing about Java, which makes it inherently unsuitable for highly multithreaded applications.

+10
source

If you have 4 cores, the optimal thread pool size can be 4, as this is the minimum number of threads needed to keep all processors busy. However, you can have any number of idle / waiting threads up to 10K. This is the polling point of the JVM thread library, so switching to Scala will not make any difference. Note: you can have many more threads, I would not recommend it.

If you have 10K streams and want more, I suggest you buy another server. You can buy a lot for the server for about $ 1,000.

I tested the test by creating many threads on my machine, upgrading to Java 6 26, 32-bit and 64-bit on Ubuntu 11. The first 1000 threads took 72 ms to create, starting from 31K to 32K, they took 3,861 ms to create. With approximately 32K threads, I got this error

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:640) 
+1
source

I once conducted threading experiments to find out if there is a significant difference between Linux and Windows, and to hit a kind of barrier of about 2,000 threads on both platforms. The test was several years old, and I did not repeat it, but later I found the same number that others were talking about, but I did not save the link.

Without testing, I think you're right about scala. The techniques used there - Actors - work with smaller objects, afayku, but I can not give you numbers.

+1
source

@ user84592: not sure about my answer, just brainstorming. How about installing virtual machine software on this computer by distributing CPU cores to it, it will create many machines instead of one physical machine, and then you can put a load on the java application for each of them ...

0
source

Source: https://habr.com/ru/post/892984/


All Articles