In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to configure the optimization of Tomcat user management". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Tomcat user Management configuration
To add a user to tomcat-users.xml:
Click server status to enter the user name and password to view the status of the server
1. Server information
2. JVM information (these values are very low by default, which we can configure)
The younger generation of PS Eden Space:JVM. After an object new comes out, it will be Eden Space until the GC arrives. GC will ask each object one by one whether there are references, enter the Survivor Space (survival area), and no references will be kill.
The old age of PS Old Gen:JVM.
PS Survivor Space: survival area. The objects in the survivor area can live for a period of time, and GC will access these objects regularly (which can be customized). If the reference to the object no longer exists, it will be kill. If there is a reference to the object every time you visit it, it will be transferred to the old age. (used to save objects in the eden space memory pool that have not been reclaimed after garbage collection. )
Code Cache: code cache. The HotSpot Java virtual machine includes a memory for compiling and saving native code (native code).
PS Perm Gen: eternal generation.
Optimization of tomcat I. Optimization of three operation modes in tomcat
1. BIO (blocking): the default mode of tomcat, which has low performance and does not have any optimization and support, and one thread processes a request. Disadvantages: when the concurrency is too large, there are more threads and resources are wasted. Tomcat7 and below, this mode is used by default in linux systems.
2. NIO-Non-blocking IO (non-blocking IO): Java NIO allows you to use IO non-blocking, for example, when a thread reads data from a channel to a buffer, the thread can still do other things. When the data is written to the buffer, the thread can continue to process it. Writing a channel from a buffer is similar. Tomcat8 uses this approach by default in Linux systems.
3. APR:Apache Portable Runtime to solve the problem of io blocking from the operating system level. This is the default way to start Tomcat7 or Tomcat8 on systems with Win7 or above. Linux supports apr if apr and native,Tomcat are installed and started directly.
(installation method: https://www.yisu.com/os/78408.html)
View the startup mode of tomcat:
Modify the operation mode of tomcat:
Modify protocol= "HTTP/1.1" to NIO mode
After modification:
Ps: this is the first step in optimizing tomcat, optimizing the operation mode of tomcat
3. Http information
II. Optimization of tomcat executor (thread pool)
Thread pooling is not enabled by default in tomcat, and every user request in tomcat is a thread, so we can use thread pooling to improve performance. There is a scheduling thread in the first segment of tomcat, which puts the user's request into the thread pool, and after a certain period of time, the user request task in the thread pool becomes a worker thread.
1. Open thread pool: open the configuration of thread pool in server.xml
Important parameters description:
Name: the name of the shared thread pool. This is the name that Connector will reference in order to share the thread pool, and the name must be unique. Default value: None
NamePrefix: on JVM, each running thread can have a name string. This property sets a prefix to the name string for each thread in the thread pool and Tomcat appends the thread number to this prefix. Default value: tomcat-exec-
MaxThreads: the maximum number of threads this thread pool can hold. Default value: 200
MaxIdleTime: the amount of time (in milliseconds) that idle threads are allowed to last before tomcat shuts down an idle thread. Idle threads will be closed only if the number of currently active threads is greater than the value of minSpareThread. The default value is 60000 (one minute).
The minimum number of inactive threads that minSpareThreads:Tomcat should always open. Default value: 25.
2. Reference thread pool
One of the best configurations of PS:Connector: in general, we don't use Executor to open the thread pool, we configure it directly on Connector.
MaxThreads: maximum number of threads
MinSpareThreads: minimum number of threads
AcceptCount: accept maximum queue length
MaxConnections: maximum connections
ConnectionTimeout: timeout wait time millisecond
MaxHttpHeaderSize: maximum request header
TcpNoDelay: if true, the server socket sets the TCP_NO_DELAY option, which improves performance in most cases. Set to true by default
Compression: whether to enable compression GZIP on enable off turn off forde: compression in all cases
DisableUploadTimeout: limit upload time
EnableLookups: turn off DNS reverse query. DNS reverse query takes time.
Third, disable AJP connector for tomcat optimization to achieve static and dynamic separation.
AJP: the protocol is packet oriented. The web server and the servlet container interact through TCP links, and to save the expensive cost of SOCKET creation, the WEB server attempts to maintain a permanent TCP link to the Servlet container and reuses the link during multiple request and response cycles.
Web client 1 can directly access the resources of the tomcat server index.jsp. If we visit static resources, tomcat is not convenient to deal with. It will return these static resources to the Apache server, and they will return them to the users, so the tomcat server is less efficient in dealing with static resources than the nginx server. Therefore, our web server is generally Nginx+tomcat,nginx responsible for handling static resources, so the AJP protocol we can turn it off when using the nginx+tomcat architecture for efficiency optimization.
Just comment on the server.xml in tomcat.
IV. Optimization of JVM parameters in tomcat
The optimization of jvm parameters is mainly the optimization of heap memory, which is divided into three parts: young generation, old generation and permanent generation.
How to allocate the size of these three areas:
If our requirements need to create objects frequently and will be recycled immediately after using them, we can allocate more space to the younger generation. For example: provide a query interface to return json data, this interface is called frequently, we can increase the space of the young generation of this service.
The old space can be set larger when there are more static variables.
1. Set the heap memory size
-Xms:JVM initializes memory
After JVM starts, the maximum heap memory of-Xmx:JVM will be allocated the memory space specified by the-Xmx parameter as heap memory, but not all of it will be used. JVM will adjust the memory really used for JVM according to the-Xmx parameter.
The difference between-Xmx and-Xms is the size of the three Virtual spaces.
2. The younger generation
-xx:NewRatio=8 says the ratio of the older generation to the younger generation is 8:1
-XX:SurvivorRatio=32 indicates that the ratio of eden to survivor is 32:1
-Xmn means to set the size of the younger generation
3. Permanent generation
-XX:PermSize=16m-XX:MaxPermSize=64M
4. Thread Stack (thread area)
-XX:Xss=128k
Modify the catalina.bat or catalina.sh file in the tomcat bin directory as follows
Catalina.bat under windows
Rem-set JAVA_OPTS=-Dfile.encoding=UTF-8-server-Xms1024m-Xmx2048m-XX:NewSize=512m-XX:MaxNewSize=1024m-XX:PermSize=256m-XX:MaxPermSize=512m-XX:MaxTenuringThreshold=10-XX:NewRatio=2-XX:+DisableExplicitGCsetlocal
Catalina.sh under Linux
#-JAVA_OPTS= "- Dfile.encoding=UTF-8-server-Xms1024m-Xmx2048m-XX:NewSize=512m-XX:MaxNewSize=1024m-XX:PermSize=256m-XX:MaxPermSize=512m-XX:MaxTenuringThreshold=10-XX:NewRatio=2-XX:+DisableExplicitGC" # OS specific support. $var _ must_ be set to either true or false.
Parameter description:
#-Dfile.encoding: default file encoding #-Xms512m sets the minimum memory of JVM to 512m, which can be set to the same value as-Xmx to prevent JVM from reallocating memory after each garbage collection. #-Xmx1024 sets JVM maximum available memory #-XX:NewSize sets young generation size #-XX:MaxNewSize sets young generation maximum memory size #-XX:PermSize sets permanent generation size #-XX:MaxPermSize sets permanent generation maximum memory #-XX:NewRatio=2 sets the ratio of young generation to old generation 2: indicates that the ratio of young generation to old generation is the maximum age of garbage like 1:2#-XX:MaxTenuringThreshold. The default is 15. 0: indicates that the younger generation enters the old era directly without going through the Survivor area. For more applications in the old era, setting it to 0 can improve the efficiency. If the value is high, it means that the object of the younger generation will be copied multiple times in the Survivor area, so as to increase the survival time of the object in the younger generation and increase the probability of being recycled in the younger generation. # XX:+DisableExplicitGC applications will ignore receiving code that calls GC. And System.GC () is an air conditioner. "how to optimize the configuration of Tomcat user management" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.