Processing Method for memory overflow and downtime of apusic application server after File Upload

Source: Internet
Author: User

A strange phenomenon occurred several days ago. Continuous File upload operations may cause JVM memory overflow, and Java. Lang. outofmemoryerror: permgen space may cause permanent memory overflow. Eventually, the entire apusic application server goes down.

For permanent generation space, JVM does not clean up garbage during runtime. This memory overflow is generally caused by too many classes loaded, exceeding the default JVM value or the set value. The general solution is to increase the size of permanent generation space.

However, here we will increase the maxpermsize from 256 MB to MB, so the same problem occurs after uploading some files. It is estimated that the overflow will be a matter of time. When the application is started, everything is normal, indicating that loading the class file of the application is not a problem. Adding maxpermsize makes no sense to solve the problem.

However, how does the file upload operation cause permgen space overflow? Do you want to understand?

Monitor the application logs.

During the entire application operation, everything is normal, and the SQL statements generated by the debug persistent layer framework are normal, but at some time points, the following information is always displayed at irregular time points:

18:03:08 info [apusic. web. office. /Office] Closing spring root WebApplicationContext2011-04-26 18:03:08 info [apusic. web. office. /Office] Shutting Down log4j2011-04-26 18:03:08 info [apusic. application. office] stopped.2011-04-26 18:03:09 info [apusic. web. office. /Office] initializing spring root webapplicationcontext

I don't understand why do applications always need to be restarted?

I can see that the application will be restarted frequently. When the application is restarted, permanent generation space will always Reload all the class files, the JVM does not collect garbage from permanent generation space, which eventually results in memory overflow!

This is just speculation. Find evidence! At last, after several frequent file upload operations, the long-time exceptions were highlighted! The exception is that the entire session is lost every time a file is uploaded.

18:05:17 info [apusic. web. office. /Office] Closing spring root WebApplicationContext2011-04-26 18:05:17 info [apusic. web. office. /Office] Shutting Down log4j2011-04-26 18:05:17 info [apusic. application. office] stopped.2011-04-26 18:05:18 info [apusic. web. office. /Office] initializing spring root WebApplicationContext2011-04-26 18:05:28 error [con. err] exception in thread 'autodeployer' 18:05:28 error [con. err] Java. lang. outofmemoryerror: permgen Space

It seems that an exception occurred when the application was restarted again, and the permanent generation of memory overflow exceeded! It is enough to prove that the permanent generation overflow is related to the continuous restart of the application, and the downtime of apuisc is directly related to the continuous automatic restart of the application. The problem is found! However, why does the application continuously restart automatically? After confirming that the code is okay (I believe that any responsible programmer will restart the application without moving, and the Java EE specifications should be considered for security, will not be allowed to restart the application from the application), more to the analysis of apusic. Under what circumstances will apusic automatically restart the application?

Is the file in the Application changed? Will the user directly upload the file to the current application directory, and the current application will be placed in the default application directory of apusic, so that once some files under the default application change, whether the file is added, modified, or deleted, apusic will generate corresponding measures to ensure timely loading of changed files.

After communicating with the Headquarters (here, I would like to thank colleagues from the headquarters, such as Li weibin and Wei yongsen, for their strong support to solve the problem). This is the final confirmation of the problem, after the upload directory is migrated from the application, everything is normal!

 

In short, if the file to be uploaded is stored in a directory of the current application, and the application is placed in the default application directory of apusic, it is unfortunate that every time a file is uploaded, apusic automatically restarts the application to ensure timely file loading.

 

Therefore, it is recommended that if the file is not converted to a binary stream and stored in the database during file upload operations, it is best to put the file storage issue out of the application, at least the directories parallel to the application can be done, or even an absolute path can be specified, which is not a good thing for file management.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.