In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the content of a sample analysis of jvm's support for maximum number of threads testing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Recently, if you want to test the maximum number of concurrency under Openfire, you need to open a large number of threads to simulate the client. There are always doubts about how many threads a JVM instance can run, so I intend to test it simply by google, and find the following factors that affect the number of threads:
-Xms
Intial java heap size
-Xmx
Maximum java heap size
-Xss
The stack size for each thread
System restriction
Maximum number of open threads in the system
The test procedure is as follows: Java code:
Import java.util.concurrent.atomic.AtomicInteger; public class TestThread extends Thread {private static final AtomicInteger count = new AtomicInteger (); public static void main (String [] args) {while (true) (new TestThread ()) .start ();} @ Override public void run () {System.out.println (count.incrementAndGet ()); while (true) try {Thread.sleep (Integer.MAX_VALUE) } catch (InterruptedException e) {break;}
Test environment: system: Ubuntu 10.04 Linux Kernel 2.6 (32 bit)
Memory: 2G
JDK:1.7
Test results:
Do not consider system limitations
-Xms
-Xmx
-Xss
Result
1024m
1024m
1024k
1737
1024m
1024m
64k
26077
512m
512m
64k
31842
256m
256m
64k
31842
No threads can be created in the system when the number of threads created reaches 31842.
From the above test results, it can be seen that increasing heap memory (- Xms,-Xmx) reduces the number of threads that can be created, and increasing thread stack memory (the minimum value of this parameter in the-Xss,32 bit system is 60K) also reduces the number of threads that can be created.
A combination of system limitations
The limit of 31842 threads is determined by the maximum number of threads that the system can generate: / proc/sys/kernel/threads-max, but the default value is 32080. Modify its value to 10000:echo 10000 > / proc/sys/kernel/threads-max, and the modified test results are as follows:
-Xms
-Xmx
-Xss
Result
256m
256m
64k
9761
In that case, does that mean you can configure as many threads as possible? Modify it again: echo 1000000 > / proc/sys/kernel/threads-max. The modified test results are as follows:
-Xms
-Xmx
-Xss
Result
256m
256m
64k
32279
128m
128m
64k
32279
It was found that the number of threads did not grow after reaching 32279. Check that the maximum number of pid that can be created in a 32-bit Linux system is 32678, which can be modified through / proc/sys/kernel/pid_max (the modification method is the same as threads-max), but in 32 systems this value can only be reduced, not larger. If the threads-max is certain, the test results corresponding to the modified pid_max are as follows:
Pid_max
-Xms
-Xmx
-Xss
Result
one thousand
128m
128m
64k
five hundred and eighty two
10000
128m
128m
64k
9507
The situation should be similar on Windows, but there may be fewer threads that can be created than on Linux,Windows. Servers based on the threading model are always limited by the number of threads.
The maximum number of threads that can be generated in JVM is affected by the heap memory size of JVM, the Stack memory size of Thread, and the maximum number of threads that can be created by the system (the implementation of Java threads is based on the thread mechanism of the underlying system, and pthread_create under _ beginthreadex,Linux under Windows). The amount can be estimated based on the maximum memory that the Java process can access (typically 2G on 32-bit systems), heap memory, and Thread's Stack memory.
Preface:
Tested on a 64-bit Linux system (CentOS6,3G memory), it is found that there is another parameter that limits the number of threads: maxuserprocess (which can be viewed through ulimit-a, the default value is 1024, which can be modified through ulimit-u), which is unlimited in the above 32-bit Ubuntu test environment.
Modify the values of threads-max,pid_max,maxuserprocess, these three parameters to 100000Lecture XmsLay Xmx as small as possible (128m 64m),-Xss as small as possible (minimum 104k under 64 bits, available value 128k). It is predicted in advance that in such a test environment, the number of threads will only be limited by the memory size of the test environment (3G), but the actual test result is that when the number of threads reaches 32K (32768, the maximum number of threads is about 33000), JVM throws a warning: Attempttoallocatestackguardpagesfailed, and then OutOfMemoryError cannot create local threads. After looking at the memory, it is found that there is still a lot of free time, so it should not be the cause of the memory capacity. Google this warning is fruitless, temporarily do not know what reason, need to be further studied.
Preface 2:
Today, I accidentally found article [7]. I immediately tried it. Sure enough, this factor will affect the number of threads created. According to the description in the article, the number of / proc/sys/vm/max_map_count doubled, from 65536 to 131072, the total number of threads created reached 65000 cycles, and the computer was basically stuck (3G memory). Briefly check the role of this parameter, as described in [8]:
"Thisfilecontainsthemaximumnumberofmemorymapareasaprocessmayhave.Memorymapareasareusedasaside-effectofcallingmalloc,directlybymmapandmprotect,andalsowhenloadingsharedlibraries.
Whilemostapplicationsneedlessthanathousandmaps,certainprograms,particularlymallocdebuggers,mayconsumelotsofthem,e.g.,uptooneortwomapsperallocation.
Thedefaultvalueis65536. "
OK, this problem is finally solved satisfactorily. Finally, we summarize the factors that affect the number of Java threads:
The Java virtual machine itself:-Xms,-Xmx,-Xss
System restrictions:
/ proc/sys/kernel/pid_max
/ proc/sys/kernel/thread-max
Max_user_process (ulimit-u)
/ proc/sys/vm/max_map_count .
Thank you for reading! This is the end of the article on "sample Analysis of jvm supporting maximum Thread Test". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.