ArticleDirectory
- Appendix 2:
- Appendix 3:
- Appendix 4:
Zheng Yi 201102
1. Number of file handles
Symptom 1: Error 500 is displayed when you access the page. The error description is:Java. Lang. noclassdeffounderrorThe class names that follow are not listed one by one.
Symptom 2: Resin is automatically restarted by wathcdog. The log shows that this is because:Resin Shutdown From out of file descriptors.
Analysis:Because the default file handle in Linux is limited to 1024 (which can be viewed through the ulimit-N command), when the web server handles a large number of threads for high loads, there are many incoming socket connections and outgoing socket connections, and the backgroundCodeIt may also involve opening a large number of handles, especially STRUTS + spring combinations.
Therefore, when the number of handles quickly reaches the limit of 1024, the new handle cannot be opened, because the file cannot be opened, the class definition cannot be found, and such errors occur.
Solution:
The short-term policy is to increase the limit on the number of file handles in Linux. See Appendix 1. For this number, it is generally recommended that it be 32667, or you can set it to a larger value. We can adjust it to 51200 directly.
2. permsize Problems
Symptom: After the resin is continuously accessed for a period of time, for example, one day, the following error 500 will be reported, resulting in access failure to all pages:
Outofmemoryerror: permgen Space
At this point, you can only restart the machine, and restarting resin is useless.
Analysis: Because spring + Struts is used online, these frameworks use a large number of dynamic classes. classloader places this part of memory in permgen space. The GC of JVM will not clean up permgen space. This can easily cause the online application report permgen space memory overflow.
Solution: By adding a series of JVM-Arg parameters to resin. XML, increase the parameters "permsize" and "maxpermsize" to avoid JVM memory permanent storage overflow errors. For the default permsize value, see appendix 2. For more information, see Appendix 3.
3. xmx and XMS Problems
Symptom: Resin reported the following 500 error, causing Access to All pages:
Outofmemoryerror: Java heap Space
Restart resin and restore it.
Analysis: By default, the maximum available memory (-xmx parameter) and initial heap size (-XMS parameter) of JVM are both small, which can easily restrict the server capabilities. When the Java architecture capabilities are not fully utilized, the system has been limited by various default parameters, resulting in various exceptions.
Solution: Add JVM-Arg parameters to resin. XML to increase the parameters "XMS", "xmx", and "xmn. For more information, see Appendix 3. Xmn Appendix 4.
The xmx value can be set to a large value, for example, 4096 mb. The difference between the xmx value and your physical memory size is not too large. It is supported by 64-bit Linux. The xmn value is 1/4 of the xmx value.
The value of XMS can be the same as that of xmx. After proper pressure is saved, the initial heap size is not enough. The JVM has to spend time expanding the memory size to the maximum available memory value, in this process, continuous high load may have overwhelmed the server. This mechanism is similar to the well-known SQL Server. We need to carefully consider specifying the initial and maximum database space values and the self-growth mode based on the business needs. By default, the automatic growth of SQL Server database space increases by 10%: If you allocated 1 GB space at the beginning of the database creation, when the pressure increases, the data will soon reach 1 GB, the database will lock all requests and automatically increase the disk space by MB. During this automatic growth process, all Web requests will be suspended, and eventually all requests may time out.
Appendix
Appendix 1:
Edit/etc/profile and add
Ulimit-N 51200
Some people think that it can be set to 4096, but it is best to set this number to tens of thousands on the network server, otherwise the traffic is too easy to break through.
You can also set the following two parameters: ulimit-shn 51200,-S, and-h:
-H: Set hardware resource limits.
-S: Sets Software resource limits.
-N size: sets the maximum value of the file descriptor that the kernel can open at the same time.
There is another way to modify the settings in three places, see modify Ubuntu ulimit restrictions.
Appendix 2:
If permsize is not added to resin. XML, the default calculation rule is:
"JVMUse-XX: permsizeSet the non-heap memory initial value. The default value is 1/64 of the physical memory.; By XX: maxpermsizeSets the maximum non-heap memory size. The default value is 1/4 of the physical memory.."
Therefore, if the physical memory is 4 GB, one of the 64 points is 64 MB, which is the default permsize, that is, the initial memory size of the permanent generation;
1/4 is 1024 MB, which is the default maxpermsize.
Appendix 3:
Optimization rules: it is best to set-XMS and-xmx to the same value on the server-side JVM. To optimize GC, it is recommended that the-xmn value be approximately 1/4 of-xmx.
Add the following configuration nodes to the resin. xml file of online resin 4.0.15:
<Server-default>
<JVM-Arg>-xms4096m </JVM-Arg>
<JVM-Arg>-xmx4096m </JVM-Arg>
<JVM-Arg>-xmn1024m </JVM-Arg>
<JVM-Arg>-XX: permsize = 128 M </JVM-Arg>
<JVM-Arg>-XX: maxpermsize = 256 m </JVM-Arg>
<Thread-max> 1024 </thread-max>
<Socket-Timeout> 30 S </socket-Timeout>
<Keepalive-max> 512 </keepalive-max>
<Keepalive-Timeout> 60 S </keepalive-Timeout>
</Server-default>
Appendix 4:
The-xmn parameter of JVM indicates the heap size of young generation.
JVM has two GC threads. The first thread is responsible for revoking heap's young zone. When the heap is insufficient, the second thread traverses the heap and upgrades the young area to the older area. The size of the older area is equal to-xmx minus-xmn, and the value of-XMS cannot be set too large, because the second thread is forced to run will reduce JVM performance.