In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to set up Tomcat memory. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
I. configuration
Tomcat/conf/server.xml modifies configuration
"8080" protocol= "org.apache.coyote.http11.Http11NioProtocol" redirectPort= "8443" URIEncoding= "UTF-8" minSpareThreads= "25" maxSpareThreads= "300" maxThreads=" 500" acceptCount= "500" connectionTimeout= "30000" enableLookups= "false" / > II. Parameter description
MaxIdleTime: if the maximum idle time exceeds this idle time and the number of threads is greater than minSpareThreads, it will be recycled. The default is 1 minute (60000ms).
MinSpareThreads: the minimum number of idle threads, the number of threads that will survive under any circumstances, and will not be recycled even if the maximum idle time is exceeded. The default value is 4.
MaxSpareThreads: the maximum number of idle threads, which is active within the maximum idle time (maxIdleTime). If the idle time is greater than maxIdleTime, it will be reclaimed. If it is smaller, it will continue to survive and wait to be scheduled. The default is 50.
MaxThreads: maximum number of threads. For large concurrent requests, the maximum number of threads that tomcat can create to process requests. If the number exceeds, it is queued in the request queue. The default value is 200.
AcceptCount: when the maximum number of threads (maxThreads) is used up, you can put the number of queues in the request queue. If you exceed this number, return connection refused (request rejected), general settings and max.
Threads is the same, but this needs to be weighed according to the actual peak and average access of your application. The default value is 100.
ConnectionTimeout: the network connection timed out. If you set it to 0, you will never time out. This is a very dangerous setting. You can usually set it to 30000ms, which is the default 60000ms.
Windows Tomcat allows maxThreads per process (maximum number of threads) 2000
Linux Tomcat allows maxThreads per process (maximum number of threads) 1000
Diagram the principle of thread pool
Take a look at the following three situations
Case 1: accept a request and the number of threads started by tomcat does not reach maxThreads,tomcat will start a thread to process the request.
Case 2: accept a request when the number of threads started by tomcat has reached maxThreads,tomcat. The request will be placed in a waiting queue for idle threads.
Case 3: accept a request, when the number of threads started by tomcat has reached maxThreads, and the number of requests in the waiting queue has also reached acceptCount, tomcat will directly reject the request and return connection refused
How to configure maxThreads
General server operations include quantity aspects: 1 computing (mainly consuming cpu), 2 waiting (io, database, etc.)
In the first extreme case, if our operation is pure computing, then the main limitation of the system response time is the computing power of cpu. At this time, maxThreads should be set as small as possible to reduce the number of threads competing for cpu at the same time, which can improve computational efficiency and improve the overall processing capacity of the system.
In the second extreme case, if our operation is purely IO or database, then the main limit of response time is to wait for external resources, and the maxThreads should be set as large as possible, so as to increase the number of requests processed at the same time, and thus improve the processing capacity of the system as a whole. In this case, because the number of requests processed by tomcat at the same time will be relatively large, you need to pay attention to the virtual machine memory setting of tomcat and the open file limit of linux.
When I was testing, I encountered a problem. I set a relatively large maxThreads, such as 3000. When the number of threads in the service is large to a certain extent, it is usually just over 2000, and the response time for a single request will increase sharply. I wonder why this is why it is useless to look for answers everywhere. Finally, the reason I summarize may be that cpu consumes more and more time during thread switching with the increase in the number of threads. Cpu spends most of his time switching directly between these 2000 threads, and of course cpu doesn't have time to deal with our program. In the past, it was simply thought that multithreading = high efficiency. In fact, multithreading itself can not improve the efficiency of cpu, too many threads will reduce the efficiency of cpu. When number of cpu cores
In real applications, our operations will include the above two types (calculation, waiting), so the configuration of maxThreads does not have an optimal value, must be configured according to the specific situation. The best way is: on the basis of continuous testing, continuous adjustment and optimization, in order to get the most reasonable configuration.
The configuration of acceptCount is generally set to be as large as maxThreads. This value should be weighed mainly according to the peak and average access of the application.
If the setting is small, the accepted request can be guaranteed to respond quickly, but the excess request may be rejected directly.
If the setting is large, there may be a large number of request timeouts, because the processing capacity of our system is certain.
These are all the contents of the article "how to set up Tomcat memory". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.