In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to modify the memory configuration of Tomcat. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
I. configuration
Tomcat/conf/server.xml modifies configuration
Second, 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
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.