Maximum number of Tomcat connections

Source: Internet
Author: User
Tags garbage collection xms jconsole
How the following parameters of the context element should fit in Tomcat's Server.xml

<connector port= "8080"
Maxthreads= "150"
Minsparethreads= "25"
maxsparethreads= "75"
acceptcount= "100"
/>

Answer Yue:

Maxthreads= "150" means to handle up to 150 connections at the same time
Minsparethreads= "25" means that even if no one uses it to open so many empty threads to wait
maxsparethreads= "75" means that if you can empty up to 75 threads, such as 80 people at a time and no one accesses them, then Tomcat does not retain 80 empty threads, but instead closes 5 empty.

acceptcount= "100" when the number of simultaneous connections reaches MaxThreads, you can also receive a queued connection, and the connection is returned directly to the reject connection.

According to your configuration recommendations
Maxthreads= "500"
minsparethreads= "100" If your site has a large number of frequent visits, the default is open relatively large
maxsparethreads= "300"
acceptcount= "100"
It's just that your server can support so many users, but it depends on what you have installed and whether your program is efficient enough.

(second method)

Several configuration instructions in Tomcat

How to increase the number of Tomcat connections


In the configuration in the Tomcat configuration file Server.xml, the parameters associated with the number of connections are:
Minprocessors: Minimum number of idle connection threads to improve system processing performance with default value of 10
Maxprocessors: Maximum number of connection threads, that is, the maximum number of requests that are processed concurrently, with a default value of 75
Acceptcount: Maximum number of connections allowed, should be greater than or equal to Maxprocessors, default is 100
Enablelookups: Whether to reverse the domain name, the value is: TRUE or false. To improve processing power, set to False
ConnectionTimeout: Network connection timeout, in milliseconds. A setting of 0 means never time out, and this setting is hidden. Typically, it can be set to 30000 milliseconds.

The parameters associated with the maximum number of connections are maxprocessors and Acceptcount. If you want to increase the number of concurrent connections, both of these parameters should be increased.


The maximum number of connections allowed by Web server is also subject to the kernel parameter settings of the operating system, typically Windows is 2000 or so, and Linux is about 1000. How to set these parameters in Unix, see Common UNIX monitoring and Management commands

Examples of configurations in TOMCAT4:
port= "8080" minprocessors= "ten" maxprocessors= "1024"
Enablelookups= "false" redirectport= "8443"
Acceptcount= "1024" debug= "0" connectiontimeout= "30000"/>

For listening configuration for other ports, and so on.

2. How to disable files in the column directory in Tomcat
In {tomcat_home}/conf/web.xml, set the listings parameter to False, as follows:

...

Listings
False


---------------------------------------------------------------




Linux under Tomcat set maximum number of connections, set maximum memoryUnder Linux, Tomcat sets the maximum number of connections, sets maximum memory, and uses Jconsole to monitor 1. Add Tomcat Administrator account
Add Administrator account Tomcat-users.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<tomcat-users>
<role rolename= "Tomcat"/>
<role rolename= "Role1"/>
<role rolename= "Manager"/>
<role rolename= "admin"/>
<user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>
<user username= "Both" password= "Tomcat" roles= "Tomcat,role1"/>
<user username= "Role1" password= "Tomcat" roles= "Role1"/>
<user username= "admin" password= "admin123" roles= "Admin,manager"/>
</tomcat-users>

2. Tomcat Memory
Rationale: When a Java program starts, the JVM allocates both an initial memory and a maximum memory to the application. This initial memory and maximum internal presence will affect the performance of the program. For example, when the application uses the maximum memory, the JVM is going to do the garbage collection action, releasing some memory occupied. So when you want to adjust the initial and maximum memory for Tomcat startup, you need to declare to the JVM that normal Java programs can be run by-XMS-XMX to adjust the initial and maximum memory of the application: such as: java-xms64m-xmx128m Application.jar.

Method 1: If you are using the tomcat_home/bin/catalina.sh (Linux) or Catalina.bat (win) Startup:
Modify the corresponding file and add the following sentence:
Java_opts= ' $JAVA _opts-server-xmx800m-xms512m-xx:maxnewsize=256m-xx:maxpermsize=256m-djava.awt.headless= True '--ms is the minimum memory, MX is the maximum memory. This sets the minimum memory to 512M and the maximum memory is 800M. $JAVA _opts is reserved for previous settings. Catalina_opts seems to be used indiscriminately with java_opts. [For Catalina.bat It is so set: Set java_opts=-xms1024m-xmx1024m]

Method 2: If the Winnt service you are using starts:
Type regedit at the command line to find Hkey_local_machine-->software-->apache SOFTWARE foundation-->procrun 2.0-->tomcat5-- >parameters Java,
To modify the value of the options, add a new property:
-xms64m
-xmx128m or directly modify JVMMX (maximum memory) and JVMMS (minimum memory).

It has been suggested that the value of XMS and xmx be as good as possible, and that the speed of memory recovery can be accelerated.
After you have modified it, you can access http://127.0.0.1:8080/manager/status to view the memory size.

You can also write a JSP page that tests the size of tomcat memory below:
<%
Runtime lruntime = Runtime.getruntime ();
OUT.PRINTLN ("* * * BEGIN MEMORY STATISTICS ***<br/>");
Out.println ("Free Memory:" +lruntime.freememory () + "<br/>");
Out.println ("Max Memory:" +lruntime.maxmemory () + "<br/>");
Out.println ("Total Memory:" +lruntime.totalmemory () + "<br/>");
OUT.PRINTLN ("Available Processors:" +lruntime.availableprocessors () + "<br/>");
OUT.PRINTLN ("* * * END MEMORY STATISTICS * * *");
%>

3. Increase the number of Tomcat connections
In the configuration in the Tomcat configuration file Server.xml, the parameters associated with the number of connections are:
Minprocessors: Minimum number of idle connection threads to improve system processing performance with default value of 10
Maxprocessors: Maximum number of connection threads, that is, the maximum number of requests that are processed concurrently, with a default value of 75
Acceptcount: Maximum number of connections allowed, should be greater than or equal to Maxprocessors, default is 100
Enablelookups: Whether to reverse the domain name, the value is: TRUE or false. To improve processing power, set to False
ConnectionTimeout: Network connection timeout, in milliseconds. A setting of 0 means never time out, and this setting is hidden. Typically, it can be set to 30000 milliseconds. The parameters associated with the maximum number of connections are maxprocessors and Acceptcount. If you want to increase the number of concurrent connections, both of these parameters should be increased. The maximum number of connections allowed by Web server is also subject to the kernel parameter settings of the operating system, typically Windows is 2000 or so, and Linux is about 1000.
Such as:
<connector port= "8080"
Maxthreads= "150"
Minsparethreads= "25"
maxsparethreads= "75"
acceptcount= "100"
/>
Maxthreads= "150" means to handle up to 150 connections at the same time
Minsparethreads= "25" means that even if no one uses it to open so many empty threads to wait
maxsparethreads= "75" means that if you can empty up to 75 threads, such as 80 people at a time and no one accesses them, then Tomcat does not retain 80 empty threads, but instead closes 5 empty.

acceptcount= "100" when the number of simultaneous connections reaches MaxThreads, you can also receive a queued connection, and the connection is returned directly to the reject connection.

4. Using Jconsole monitoring
Add the following statement to the TOMCAT_HOME/BIN/CATALINA.SH (Linux) file that you want to monitor: java_opts= "$JAVA _opts-dcom.sun.management.jmxremote.port= 8089
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=false "
Sets a new port number. Then in the native DOS input jconsole command, pop-up "JAVA Monitoring and Management Console", if it is remote monitoring, input Legend has it that it can add a word "-djava.rmi.server.hostname=192.168.1.80" did not try to ⊙﹏⊙ b Khan first copied a sentence, leaving it as a memory:

Find the JMX configuration of remote Tomcat, and have a parameter-djava.rmi.server.hostname=ip_or_hostname. Then I added the IP of the server. And then we can connect. A bit puzzled by this situation, and the official did not find any explanation of this parameter. When you come back, try again. Open a Linux on the virtual machine and then match the JMX parameters (no java.rmi.server.hostname). Results can be connected. ... Why can't the company connect? Why add IP on the line. Suspect multiple network adapters. Then add a Web on the virtual machine, then start Tomcat, Hmm, can't connect (no server.hostname), then add Java.rmi.server.hostname to start Tomcat, result or connect. Originally java.rmi.server.hostname is this function.





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.