Interview questions Tomcat

最近面试了几家公司,总结了几个共性的问题。首先研究的是tomcat及先关应用。

Q1: Does tomcat load the application package first, or the package under lib first?
This question examines the understanding of the class loading mechanism.
The JVM class loading mechanism is the principle of parent delegation, that is, the subclass loader first finds that it needs to load the .class file, does not load it, and delegates to the parent class to do it, and delegates to the root class loader-BootstrapClassLoader. At this time, if the parent class loader cannot load, it will be passed to the child class to load, layer by layer until the loading is completed. This ensures that the java.long.String class you write does not override the JDK.
The principle of parent delegation is advisory, and not all are observed.
The tomcat class loading mechanism is different. Because multiple project packages can be placed under the tomcat webapp, each project package may have different versions of the same third-party jar package. If parental delegation is followed, the third-party packages will all be the same version, which is obviously Is wrong. Therefore, the tomcat class loading mechanism is reversed. The webapp loader first loads the .class files required by the project. If it cannot be loaded, it is passed up until the root loader.
Q2: What is the difference between post and get methods? Is there an upper limit on the size of the parameters passed by the get method? If so, who is restricting?
First of all, the difference between post and get methods to security, visibility, caching, etc. Needless to say, you can refer to the link below. The focus here is on the upper limit of the next parameter. There is no post, there is a get, generally 2048 characters.
But is it really possible to transfer 2048? The answer is not necessarily, limited by browser and web server, and different browsers have different restrictions. Some code friends have tested it and put it in the link below.
Q3: What is the use of port 8009 of tomcat and when?
We all know that port 8080 of tomcat is generally used to access deployed applications. It provides HTTP general services to establish links with client programs and accept client requests. Of course, this port can also be changed to what you want, in service.xml under conf.
But there is also Yege 8009 port in the configuration class. What is this used for? This is actually used for the AJP protocol and is responsible for establishing connections with other HTTP servers. This port is needed when integrating Tomcat with other HTTP servers.
Q4: Tuning tomcat?
The tuning here is divided into two parts, one is tomcat operating environment jvm tuning, and the other is tomcat itself tuning.
JVM tuning: bin \ catalina.sh (catalina.bat) file under tomcat path
set JAVA_OPTS = -server
-Xms1400M
-Xmx1400M
-Xmn170m
-Xss512k
-XX: + AggressiveOpts
-XX: + UseBiasedLocking
-XX: PermSize = 128M
-XX: MaxPermSize = 256M
-XX: + DisableExplicitGC
-XX: MaxTenuringThreshold = 31
-XX: + UseConcMarkSweepGC
-XX: + UseParNewGC
-XX: + CMSParallelRemarkEnabled
-XX: + UseCMSCompactAtFullCollection
-XX: LargePageSizeInBytes = 128m
-XX: + UseFastAccessorMethods
-XX: + UseCMSInitiatingOccupancyOnly
-Djava.awt.headless = true
server configuration indicates that tomcat has run in real production mode and will have more resources;
xms and xmx indicate the maximum and minimum heap memory used by jvm, jvm will be based on the use of the largest Dynamically adjust the memory occupied between the minimum values. But it will affect the garbage collector to switch back and forth when reclaiming memory between sizes, which takes time. Therefore, these two values ​​are generally set to be meaningful, about 1/4 of the machine's physical memory.
Xmn, the permanent generation generally has a fixed size of 64m, so increasing the young generation will reduce the size of the old generation. This value has a greater impact on system performance, Sun official recommended configuration is 3/8 of the entire heap.
Xss, the stack size of each thread, the default value is 1M, which can be adjusted according to the memory size required by the application thread. Under the same physical memory, reducing this value can generate more threads. However, the operating system also has a limit on the number of threads in a process, which cannot be generated indefinitely, and the experience value is about 3000 ~ 5000.
Generally these are almost the same.
Tomcat performance tuning: server.xml file, find port 8080 and configure it there.
maxThreads = "300": Set the current maximum number of concurrent Tomcat. The maximum number of requests configured by Tomcat is 150 by default, but in actual use, the maximum number of concurrent requests is closely related to the hardware performance and the number of CPUs. This is determined according to your own hardware.
minSpareThreads = “50”: Set the current number of threads created when Tomcat is initialized. The default value is 25.
acceptCount = “250”: When the threads of people connected at the same time reach the value set by the maxThreads parameter, they can also receive the number of queued connections. If this number is exceeded, the connection is refused directly. The default value is 100. In practical applications, if you want to increase the number of concurrent Tomcat, you should also increase the value of acceptCount and maxThreads.
enableLookups = “false”: Whether to enable domain name reverse search, generally set to false to improve processing power, its value is true, and it is rarely used.
maxKeepAliveRequests = "1": nginx is dynamically transferred to tomcat, nginx cannot keepalive, and keepalive is enabled by default on the tomcat side, and will wait for the keepalive timeout. By default, connectionTimeout is not set. So you must set tomcat's timeout and turn off tomcat's keepalive. Otherwise there will be a lot of socket timewait for tomcat. maxKeepAliveRequests = ”1” can avoid tomcat from generating a large number of TIME_WAIT connections, thus avoiding tomcat to die to a certain extent.

Reference connection:
https://blog.csdn.net/fd2025/article/details/80592099
https://blog.csdn.net/qq_44721831/article/details/98471707
https://blog.csdn.net/iteye_18297/article / details / 82158790
https://blog.csdn.net/qq_36485859/article/details/101056799

Published 6 original articles · liked 0 · visits 354

Guess you like

Origin blog.csdn.net/weixin_44863376/article/details/104979003