Solution for tomcat memory overflow caused by a JSP page, jsp page tomcat Overflow

Source: Internet
Author: User

Solution for tomcat memory overflow caused by a JSP page, jsp page tomcat Overflow

Today, my colleagues in the New Energy testing group asked me to see a strange phenomenon. A tomcat application has only one simple jsp page, and the jsp page does not have any java code (you want to use this jsp page to test the maximum QPS of tomcat on her server ). However, after a few minutes of stress testing with loadrunner, the tomcat package heap space outofmemory allocated with MB heap memory exists! The code for this page is as follows:

Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = ISO-8859-1"
PageEncoding = "ISO-8859-1" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = ISO-8859-1">
<Title> test </title>
</Head>
<Body>
<P> hello world! </P>
</Body>
</Html>

In the initial analysis, when a JSP page crashes, a corresponding java file is generated. Then, the java file is compiled into a class file and loaded into the memory. That is, a class object will be loaded into the PermGen space. It has nothing to do with heap space. However, the final message is a space overflow. Therefore, it is assumed that an object will be generated every time a jsp page is requested.

Baidu finds that a session object is generated every time a JSP page is requested. The following configuration is available in tomcat web. xml:

Copy codeThe Code is as follows:
<Session-config>
<Session-timeout> 30 </session-timeout>
</Session-config>

That is to say, a session object is generated every time a jsp page is requested, and the object expires 30 minutes later. We calculated that the QPS at that time was 5000, that is, 5000 session objects were generated every second. K objects are generated every minute, and the session is a map object, which is relatively large, so that memory will pop up soon.

The solution is as follows:

1. Add session = false to the page command.

2. Set the expiration time of the session to 0.

Now her loadrunner runs very stably. Jsp is no longer used after work. It is still laborious to query jsp problems.


How much Tomcat memory is required for a 30 M jspspace to avoid Tomcat memory overflow?

Memory overflow has nothing to do with the size of the website. The home page is the quality of the program. If the website writer has a strong technical skills, it will seldom overflow (unless the page views are too large for hardware ), this is generally the case for spam programs.

Give you a solution

1: select the space with tomcat monitoring function. When your website experiences a 500 (memory overflow), it will automatically restart tomcat for you, so that your website can be stabilized.

2: choose to regularly restart the space of the tomcat function, so that when no one is on your website, it will automatically restart tomcat for you to release your memory that will not be recycled

If you do not have these two functions, it is estimated that you will still have a memory overflow problem when hosting a server on your own, because once the memory is not recycled, it will expand infinitely, how much memory is enough for him to waste?

A question about jsp memory consumption

Isn't stream disabled?
You can delete the jsp file and rewrite the session when the session disappears.

Related Article

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.