Million threads per JVM and million threads per jvm

Source: Internet
Author: User

Million threads per JVM and million threads per jvm

I. environment requirements:
1.64bit Linux
2.64bit JDK
3. Memory is large enough, 512 GB
4. cpu: 64 processors

II. Test Tool: [DieLikeADog. java]
Java-server-Xmx6G-Xms6G-Xmn600M-Xss228K-XX: PermSize = 50 M-XX: MaxPermSize = 50 M-XX: + DisableExplicitGC DieLikeADog

III. Check Configuration:
1. ps-Lf <pid> | wc-l => View the number of threads in a process
2. ulimit-a =>
>>> Mainly view the value of-n and-u.
3. cat/proc/sys/vm/max_map_count
Permanent modification: Configure vm. max_map_count = 2048000 to/etc/sysctl. conf, and then run sysctl-p to take effect. It will also last after the OS is restarted.
You can also: [sysctl-w vm. max_map_count = 2048000]

Note: when other resources are available, the maximum number of threads that can be enabled by a single JVM is half of the number set by/proc/sys/vm/max_map_count.

Conclusion: To reach the number of threads with a JVM of more than 2048000, You need to configure vm. max_map_count = or above.
By default, vm. max_map_count = 65530. Therefore, in the default configuration, the maximum number of threads that a single jvm can enable is half a thread, that is, about threads, about 32 KB.

In practice, you can use the command cat/proc/<pid>/maps | wc-l to monitor the number of vm mappings used by the current process.
4. Maximum number of user processes: It must be modified simultaneously in the two configuration files/etc/security/limits. conf and/etc/security/limits. d/90-nproc.conf.

In fact, you only need to modify the nproc parameter 90-nproc.conf.

//// // Begin ////////
Max user processes (-u) 1024
/Etc/security/limits. conf
/Etc/security/limits. d/90-nproc.conf
* Soft nproc 10240
* Hard nproc 10240
/// // End //////////
5. file descriptor: Click [ulimit-a] To View
//// // Begin //////
Add the following configuration in/etc/security/limits. conf:

* Soft nofile 1048576
* Hard nofile 1048576
/// // End ////////
When soft and hard are the same, you can use a command as follows:
///// // Begin /////
*-Nofile 1048576
/// // End ///////
6. Adjust the network parameters: You can view them through grep ipv4/etc/sysctl. conf.
Add the following configuration in/etc/sysctl. conf:
//// // Begin /////////
Fs. file-max = 1048576
Net. ipv4.ip _ local_port_range = 1024 65535
Net. ipv4.tcp _ mem = 786432 2097152 3145728
Net. ipv4.tcp _ rmem = 4096 4096 16777216
Net. ipv4.tcp _ wmem = 4096 4096 16777216

Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ tw_recycle = 1
/// // End ////////
IV. [summary] If you only consider the maximum number of threads that a single jvm can open on the local machine, consider Step 1. If you consider the maximum number of tcp connections supported by JVM, such as in MQ,
Thread, fd, tcp, and so on are also considered, so step 1 is required.
V, Tip:
>>> Check Command
# Cat/proc/<pid>/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited seconds
Max file size unlimited bytes
Max data size unlimited bytes
Max stack size 209715200 209715200 bytes
Max core file size 0 unlimited bytes
Max resident set unlimited bytes
Max processes 204800 204800 processes
Max open files 1048576 1048576 files
Max locked memory 10485760 10485760 bytes
Max address space unlimited bytes
Max file locks unlimited locks
Max pending signals 4133863 4133863 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited us

>>> Note: in Linux, you can view the running time limit of each process in the/proc/<pid> directory.

>>> Reference: http://www.redhat.com/magazine/001nov04/features/vm/


VI. [induction]
Factors Affecting the number of Java threads ==>
Java Virtual Machine itself:-Xms,-Xmx,-Xss;
System Restrictions:
/Proc/sys/kernel/pid_max, ==> 81920 ==> corresponds to/etc/sysctl. conf ==> kernel. pid_max = 81920
/Proc/sys/kernel/thread-max, ==> corresponds to/etc/sysctl. conf => kernel. thread-max = 8192000
Max_user_process (ulimit-u)
/Proc/sys/vm/max_map_count => corresponding to/etc/sysctl. conf: vm. max_map_mount = 2048000

You need to add
==> Kernel. pid_max = 819200
Permanent modification.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.