A solution to the Tomcat memory overflow caused by a JSP page _jsp programming

Source: Internet
Author: User

Today, my colleagues from the new energy Test team came to me to see a strange phenomenon. A tomcat application with only a single JSP page, and this JSP page does not have any Java code (want to use this JSP page to test the maximum QPS of a tomcat on her server). But after a few minutes of loadrunner pressure, a 1024M heap of RAM was allocated to the heap space outofmemory! the code for this page is as follows:

Copy Code code 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" >
<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 ">
<title>test</title>
<body>
<p>hello world!</p>
</body>

The initial analysis was that a JSP page would die and produce a corresponding Java file, which would then be compiled into a class file and loaded into memory. That is, a class object will be loaded into the PermGen space. It has nothing to do with heap space. But the final report is the overflow of space. So the guess is that every time a JSP page is requested, an object is generated.

Baidu a bit, found that every time a JSP page request, will produce a session object. There's this configuration in Tomcat's Web.xml:

Copy Code code as follows:

<session-config>
<session-timeout>30</session-timeout>
</session-config>

That is, every time a JSP page is requested, a session object is generated, and the object expires after 30 minutes. We calculated that the QPS at that time was 5000, which means that 5,000 session objects per second are generated. Each minute produces 300K objects, the session is a map object, larger, so that memory will soon burst.

The solution is as follows:

1. Add Session=false to the page directive.

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

Now her loadrunner is running very steady. After work has never used JSP, check JSP problem or more laborious

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.