One 、Tomcat Of JVM Prompt for memory overflow

see %TOMCAT_HOME%\logs Under the folder , Whether the log file has a memory overflow error

Two 、 modify Tomcat Of JVM

1、 Error message :java.lang.OutOfMemoryError: Java heap space

Tomcat By default, the available memory is 128MB, In larger applications , This memory is not enough , It may cause the system to fail to operate . The common problem is to report Tomcat Memory overflow error ,Out of Memory( There is not enough memory in the system ) It's abnormal , This causes the client to display 500 error , General adjustment Tomcat The use of memory can solve this problem .

Windows Modify in environment “%TOMCAT_HOME%\bin\catalina.bat” file , Add the following settings at the beginning of the file :set JAVA_OPTS=-Xms256m -Xmx512m
Linux Modify in environment “%TOMCAT_HOME%\bin\catalina.sh” file , Add the following settings at the beginning of the file :JAVA_OPTS=’-Xms256m -Xmx512m’

among ,-Xms Set initialization memory size ,-Xmx Set the maximum memory that can be used .

2、 Error message :java.lang.OutOfMemoryError: PermGen space

reason :
PermGen space The full name is Permanent Generation space, It refers to the permanent storage area of memory , This memory is mainly used by JVM Deposit Class and Meta The information of ,Class In being Loader Will be put in PermGen space in , It and store class instances (Instance) Of Heap Different regions ,GC(Garbage Collection) Not during the main program running period PermGen space Clean up , So if you have a very CLASS Words , It's very likely that PermGen space error , This kind of mistake is common in web Server pair JSP Conduct pre compile When . If your WEB APP I used a lot of third parties jar, It's bigger than jvm Default size (4M) Then this error message will be generated .
resolvent :

Windows stay catalina.bat The first line of is added :
set JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -
XX:MaxPermSize=256m
Linux stay catalina.sh The first line of is added :
JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -
XX:MaxPermSize=256m

3、JVM Set up

The size of the pile
-Xmssize in bytes
    Set up Java The initial size of the heap , The default size is 2097152 (2MB). This value must be 1024 Bytes (1KB) Multiple , And bigger than that .(-server Option to increase the default size to 32M.)
-Xmnsize in bytes
    by Eden Object setting initial Java The size of the heap , The default value is 640K.(-server Option to increase the default size to 2M.)
-Xmxsize in bytes
    Set up Java The maximum size of the pile , The default value is 64M,(-server Option to increase the default size to 128M.) The largest stack size is nearly 2GB(2048MB).

Please note that : Many garbage collector options depend on heap size settings . Before tuning how the garbage collector uses memory space , Make sure the size of the heap is set correctly .

garbage collection : Memory usage
-XX:MinHeapFreeRatio=percentage as a whole number
    Modify the minimum percentage of memory available in the heap after garbage collection , The default value is 40. If there's at least 40% The heap memory of has not been released , The system will increase the size of the heap .
-XX:MaxHeapFreeRatio=percentage as a whole number
    Change the maximum percentage of heap memory available after garbage collection and before heap memory shrinks , The default value is 70. This means that if there are more than 70% Heap memory for , Then the system will reduce the size of the heap .
-XX:NewSize=size in bytes
    For... In an object that has been allocated memory Eden Set the default memory size for next generation . Its default value is 640K.(-server Option to increase the default size to 2M.)
-XX:MaxNewSize=size in bytes
    Allows you to change the upper limit of the initial object space , The memory needed to create a new object is allocated from this space , The default value for this option is 640K.(-server Option to increase the default size to 2M.)
-XX:NewRatio=value
    Change the scale of the old and new space , The default value for this ratio is 8, It means that the size of the new space is the size of the old space 1/8.
-XX:SurvivorRatio=number
    change Eden Size scale of object space and residual space , The default value for this ratio is 10, intend Eden The size of the object space is larger than the remaining space survivorRatio+2 times .
-XX:TargetSurvivorRatio=percentage
    Set the percentage of residual space that you expect to be used after space extraction , The default value is 50.
-XX:MaxPermSize=size in MB
    Long term generation (permanent generation) The size of the , The default value is 32(32MB).

3、 ... and 、 see Tomcat Of JVM Memory

1. Tomcat6 There is no default user set in , So we need to go to Tomcat6 Of conf Under folder tomcat-users.xml Add users... To the file .

Such as :<role rolename="manager"/>
          <user username="tomcat" password="tomcat" roles="manager"/>

notes : You need to restart after adding Tomcat6.

2. visit http://localhost:8080/manager/status, Enter the user name and password added above .

3. And then in the following JVM You can see how the memory is used in this case .

JVM

Free memory: 2.50 MB Total memory: 15.53 MB Max memory: 63.56 MB

Four 、Tomcat Connection number setting

stay tomcat The configuration file server.xml Medium <Connector ... /> Configuration in progress , Parameters related to the number of connections are :
minProcessors: Minimum number of idle connection threads , Used to improve system processing performance , The default value is 10
maxProcessors: Maximum number of connection threads , namely : The maximum number of concurrent requests , The default value is 75
maxThreads Maximum number of concurrent threads , That is, the number of tasks processed at the same time , The default value is 200
acceptCount: The maximum number of connections allowed , Should be greater than or equal to maxProcessors, The default value is 100
enableLookups: Check the domain name , The value is :true or false. In order to improve processing power , Should be set to false
connectionTimeout: Network connection timeout , Company : millisecond . Set to 0 Means never time out , There are hidden dangers in this setting . Usually it can be set to 30000 millisecond .
The parameters related to the maximum number of connections are maxProcessors and acceptCount. If you want to increase the number of concurrent connections , These two parameters should be increased at the same time .
web server The maximum number of connections allowed is also subject to the kernel parameter settings of the operating system , Usually Windows yes 2000 about ,Linux yes 1000 about .Unix How to set these parameters in , see also Unix Common monitoring and management commands

remarks :

#tomcat Memory configuration
JAVA_OPTS="-server -Xms512m -Xmx1024m -Xss1025k -XX:PermSize=128M -XX:MaxNewSize=512m -XX:MaxPermSize=256m -Djava.awt.headless=true -Djava.library.path=$JAVA_HOME/jre/lib/amd64"

<Connector port="8888" protocol="HTTP/1.1"
               maxThreads="500" minSpareThreads="50" maxSpareThreads="100" enableLookups="false" acceptCount="2000"
               connectionTimeout="20000"
               redirectPort="8443" />

Tomcat More about memory leaks

  1. Question query -tomcat Memory leak

    1. Alarm information Content : WeChat server sends messages or events to the official account , developer 5 No return in seconds frequency : 5 minute 239 Time Error examples : [OpenID=o][Stamp=1562718361][3rdUrl=url][ ...

  2. spring boot + embed tomcat + standalone jar Memory leak of

    A while ago, I met a big memory leak , Record here : One project uses spring cloud After refactoring , Deploy online ( There is an interface , About the daily dosage of 1 About a million times ), Find out zabbix In the surveillance ,linux The available memory has been ...

  3. Tomcat 6.x Perm There is a memory leak in the storage area

    Tomcat 6.x JSP The last change time of the file is greater than the current system time, resulting in Perm There is a memory leak in the storage area (java Memory pool CMS Perm Gen) A scenario : Because the test business , We need to simulate the cross day test , So one ...

  4. Java Analysis of memory leak problem of program

    What is memory leak ? The generalized Memory Leak: The application takes up memory , But no longer use ( Including not being able to use ) This part of memory The narrow sense Memory Leak: The application allocates memory , But you can no longer get a reference to that part of memory ( about Java, either ...

  5. How to use Java Writing a piece of code causes a memory leak

    This article is from StackOverflow A hot discussion on Q & a website : How to use Java Write a memory leak code . Q: I was in the interview just now , The interviewer asked me how to write a memory leak Java Code . I have no idea about this problem , ...

  6. How to use Java Writing a piece of code causes a memory leak

    Through the following steps can be very easy Generate memory leaks ( Some objects cannot be accessed by program code , But they're still in memory ): The application creates a thread that takes a long time to execute ( Or use thread pools , Memory leaks happen faster ). Thread through a class loader ( can ...

  7. Java Garbage collection mechanism and memory leak

    1.Java Introduction to memory leaks Let's first understand the concept of memory leak : Memory leak refers to the dynamic allocation of memory during program execution , But at the end of the program, this memory is not released , So this memory is not available , This is memory Let the cat out of the , Restarting the computer can solve ...

  8. 【 Wechat small program project practice summary 】30 Minutes from strange to familiar web app 、native app、hybrid app Compare 30 minute ES6 From unfamiliar to familiar 【 original 】 Talk about memory leaks HTML5 gobang - JS/Canvas game meta Detailed explanation ,html5 meta Daily tagging C# Rollback in TransactionScope How and how to use it

    [ Wechat small program project practice summary ]30 Minutes from strange to familiar Preface We have done basic study on small programs before : 1. Wechat applet development 07- How to do the list page 2. Wechat applet development 06- The completion of a business page 3. Wechat applet development 05- ...

  9. out of memory (Memory Overflow) And memory leaks (Memory Leak) The difference between

    A memory leak is when you use malloc or new Applied for a piece of memory , But it didn't pass free or delete Free up memory , Cause this memory to be occupied all the time Memory overflow means that you applied for 10 Bytes of space , But you write in this space 11 Or more bytes ...

Random recommendation

  1. C Language computing 2 The least common multiple of the number

    #include<stdio.h>int main(){   int a,b,i=1,temp,lcm;   scanf("%d %d",&a,&b); ...

  2. CSS Some basic knowledge of

    <!DOCTYPE html><html><head><meta charset="utf-8"><title> title &l ...

  3. NodeJs - 100

    Nodejs Official documents https://nodejs.org/en/docs/ Nodejs Official website https://nodejs.org/en/ Nodejs Characteristics of :  1. Use non blocking IO Mechanism :—— ...

  4. PhpStorm+PhpStudy+xdebug Configuration diagram

    1. To configure niginx.ini, newly added server node , For example, use 9200 port server { listen 9200;# Local debugging , no need 80 port server_name localhost; #cha ...

  5. C# Convert date type

    date 1999-5-31 11:20 convert to  /Date(928120800000+0800)/ among 928120800000 It's actually a 1970 year 1 month 1 Japan 00:00:00 To this DateTim ...

  6. RDD Mechanism implementation model Spark First time to know

    Spark brief introduction Spark It's a big data distributed computing framework based on memory computing .Spark Based on memory computing , It improves the real-time performance of data processing in the big data environment , At the same time, it ensures high fault tolerance and high scalability .       stay Spark in , adopt RDD( ...

  7. Linux Shell Programming (7)—— Variable assignment

    = Assignment operator ( There can't be white space on the left and right sides of it ) Don't confuse = and -eq,-eq It's a more advanced test than assignment . Be careful : be equal to (=) Depending on the environment, it may be an assignment operator or a test operator . Example : Simple variable assignment #!/b ...

  8. h5 Label Foundation meta label

    <meta> The label is located at <head> Inside the label , The specific functions are as follows : 1. Set page encoding eg: <meta charset="utf-8"/>  ,//u ...

  9. Understand the connectivity between containers - Every day 5 Minutes to play Docker Container technology (34)

    Through the practice of the previous section , At present docker host The network topology of is shown in the figure below , Today we're going to talk about connectivity between these containers . Two busybox The containers are hanging on the my_net2 On , It should be able to communicate , Let's verify : ...

  10. JavaScript in Closure Detailed explanation of

    What is a closure stay JavaScript in , Closure is a very difficult concept to understand .ECMAScript The definition of closure in is : Closure , It's a lexical representation of a function that includes variables that are not evaluated , in other words , Functions can use variables defined outside of functions . ...