Memory size set Java heap space error (Finereport report)

Source: Internet
Author: User
Tags server memory tomcat server xms

1. Problem description When querying a large amount of data from a database, each template takes out millions of data, or if the item is refreshed frequently, the template consumes a large amount of memory from the Java virtual machine JVM, and the memory will be reported Java.lang.OutOfMemoryError:Java Heap Space memory errors, the specific error is as follows: 2. Cause the error is thrown because the server's JVM is not enough The JVM automatically sets the value of the heap size when it starts, and the initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. So you can modify the JVM's-xmn-xms-xmx and other options according to your own situation. 2.1 Memory Size settingsWhen the heap size setting is small, in addition to reporting exception information, you will also find that the execution of the report slows down. The Heap size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4. The-XMS-XMN setting of the Heap size does not exceed the size of the physical memory. Otherwise you will be prompted with "Error occurred during initialization of VM Could not reserve enough space for object heap" 3. Solution 3.1 Resizing The server below we take Tomcat, for example, to see how to modify the memory size. Modify the server's memory overflow inAdd the following code to the Tomcat_home\bin\catalina.bat:
    1. Set java_opts=-xmx1024m-xms512m-xx:maxpermsize=256m
Or in the Start Program Tomcat directory under Configure Tomat Open select Java Set memory size other server memory modifications can refer to the server memory modification document. 3.2 Enable disk cache We use the default memory cache, that is, the data taken out of all in the server memory, at this time if the large amount of data is likely to lead to insufficient memory, to disk cache, is to take out the data part in memory, part of the disk, which can reduce the server memory consumption, However, reading data from disk can result in a decrease in efficiency and a growth in time.    You can see the data set cache and the shared cache to disk section for specific operations. Tomcat server concurrency View and modify 1. The problem describes when a user accesses a report, the server uses a thread to handle the report operation. If there are too many people to access and the report is computationally large, there will be a lot of participants competing for server CPU threads at the same time. Server responsiveness is reduced, so we need to have reasonable control over the number of server threads. 2. Setting method 2.1 How we can control the number of threads by modifying the configuration of the Tomcat server. Open it%tomcat_home%/conf/server.xml The document, locate the <connector port= "8080" ....> column. InConnector port = "8080" followed by the corresponding parameters to control the number of threads, the control parameters are as follows:minprocessors: Minimum number of idle connection threads for improved system processing performance with a default value ofmaxprocessors: Maximum number of connection threads, which is the maximum number of requests concurrently processed, and the default value isAcceptcount: The maximum number of connections allowed, should be greater than or equal to Maxprocessors, the default value isAfter the setup is complete, it looks like:<connector port= "8080" minprocessors= "All" protocol= "http/1.1" connectiontimeout= "20000" redirectPort= "8443" /> 2.2 Precautions the maximum number of connections allowed by Web server is also subject to the kernel parameter settings of the operating system, usually Windows is about 2000, and Linux is about 1000. The number of connections here can not directly give the best configuration, according to your actual situation, in constant adjustment, continuous testing on the basis of the most reasonable configuration.

Memory size set Java heap space error (Finereport report)

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.