MyCAT reports java. lang. OutOfMemoryError: Java heap space

Source: Internet
Author: User

MyCAT reports java. lang. OutOfMemoryError: Java heap space

In the morning, my colleague reported that mycat was suspended again. It was estimated that the memory was still overflow and I checked the error log.

INFO | jvm 1 | 07:09:06 | java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer67" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer68" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer69" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer70" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer71" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:06 | Exception in thread "Timer72" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:07 | Exception in thread "Timer74" java. lang. OutOfMemoryError: Java heap space
INFO | jvm 1 | 07:09:07 | Exception in thread "Timer73" java. lang. OutOfMemoryError: Java heap space

Heap memory overflow, which is considered to be insufficient memory, but different from the error reported in the previous days.

INFO | jvm 1 | 15:38:35 | Exception in thread "$ _ MyCatServer" java. lang. OutOfMemoryError: Direct buffer memory
INFO | jvm 1 | 15:38:35 | at java. nio. Bits. reserveMemory (Bits. java: 658)
INFO | jvm 1 | 15:38:35 | at java. nio. DirectByteBuffer. <init> (DirectByteBuffer. java: 123)
INFO | jvm 1 | 15:38:35 | at java. nio. ByteBuffer. allocateDirect (ByteBuffer. java: 306)

In addition, by checking wrapper. conf, we found that the MaxDirectMemorySize has been set to 10 Gb. At the beginning, the default value is 2 GB, and occasionally memory overflow occurs.

Wrapper. java. additional.5 =-XX: MaxDirectMemorySize = 10G

Later, a high-level expert pointed out that MaxHeapSize = 16 MB was found through the jmap-heap pid command.

Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 16777216 (16.0 MB)
NewSize = 1310720 (1.25 MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875 MB)
NewRatio = 2
Required vorratio = 8
PermSize = 21757952 (20.75 MB)
MaxPermSize = 536870912 (512.0 MB)
G1HeapRegionSize = 0 (0.0 MB)

Unscientific. The heap memory settings in wrapper. conf are not that small.

Wrapper. java. additional.10 =-Xmx4G
Wrapper. java. additional.11 =-Xms1G

# Initial Java Heap Size (in MB)
Wrapper. java. initmemory = 4G

# Maximum Java Heap Size (in MB)
Wrapper. java. maxmemory = 15G

Copy code

Finally, we found that the problem lies in wrapper. java. initmemory = 4G and wrapper. java. maxmemory = 15g.

It turns out that the two parameters can be set directly to the value, because the Unit of the parameter has been specified, which is MB.

If it is set to 15 GB, the jvm will directly block the subsequent G and use 15, and then the MaxHeapSize will be set to 16 MB (after testing, if it is set to 17, maxHeapSize is set to 18 MB. It is not clear why an even number is allocated each time ).

I tested it and came to the following conclusion:

1. the wrapper. java. maxmemory parameter will overwrite the wrapper. java. additional.10 parameter.

2. Even if the value of wrapper. java. maxmemory exceeds 4096, MaxHeapSize is up to 4096 MB.

3. If the heap size exceeds 4096 MB, you can set wrapper. java. maxmemory and comment out wrapper. java. maxmemory.

We recommend that you only use wrapper. java. additional.10 =-Xmx4G and wrapper. java. additional.11 =-Xms1G to configure the heap memory size.

Summary:

Mycat can be started in two ways.

1. mycat/bin/mycat start

In this way, mycat/conf/wrapper. conf is used as the configuration file.

Use sh-x mycat start to find out

+ Eval' "/usr/local/mycat/bin /. /wrapper-linux-x86-64 "'' "/usr/local/mycat/conf/wrapper. conf "'wrapper. syslog. ident = mycat'wrapper. pidfile = "/usr/local/mycat/logs/mycat. pid "'wrapper. daemonize = TRUE 'wrapper. lockfile = "/var/lock/subsys/mycat "'
++/Usr/local/mycat/bin /. // wrapper-linux-x86-64/usr/local/mycat/conf/wrapper. conf wrapper. syslog. ident = mycat wrapper. pidfile =/usr/local/mycat/logs/mycat. pid wrapper. daemonize = TRUE wrapper. lockfile =/var/lock/subsys/myca

2. mycat/bin/startup_nowrap.sh

This script also contains jvm configurations.

JAVA_OPTS = "-server-Xms2G-Xmx2G-XX: MaxPermSize = 64 M-XX: + AggressiveOpts-XX: MaxDirectMemorySize = 2G"

#./Startup_nowrap.sh
"/Usr/local/jdk1.7.0 _ 79/bin/java"-DMYCAT_HOME = "/usr/local/mycat"-classpath "/usr/local/mycat/conf: /usr/local/mycat/lib/classes:/usr/local/mycat/lib/curator-client-2.9.0.jar:/usr/local/mycat/lib/curator-framework-2.9.0.jar: /usr/local/mycat/lib/dom4j-1.6.1.jar:/usr/local/mycat/lib/druid-1.0.14.jar:/usr/local/mycat/lib/ehcache-core-2.6.11.jar: /usr/local/mycat/lib/fastjson-1.2.7.jar:/usr/local/mycat/lib/guava-18.0.jar:/usr/local/mycat/lib/jline-0.9.94.jar: /usr/local/mycat/lib/json-20151123.jar:/usr/local/mycat/lib/leveldb-0.7.jar:/usr/local/mycat/lib/leveldb-api-0.7.jar: /usr/local/mycat/lib/log4j-1.2.17.jar:/usr/local/mycat/lib/mapdb-1.0.7.jar:/usr/local/mycat/lib/mongo-java-driver-2.11.4.jar: /usr/local/mycat/lib/Mycat-server-1.5-GA.jar:/usr/local/mycat/lib/netty-3.7.0.Final.jar:/usr/local/mycat/lib/ojdbc14-10.2.0.3.0.jar: /usr/local/mycat/lib/sequoiadb-java-driver-1.0-20150615.070208-1.jar:/usr/local/mycat/lib/slf4j-api-1.7.12.jar:/usr/local/mycat/lib/slf4j-log4j12-1.7.12.jar: /usr/local/mycat/lib/snakeyaml-1.16.jar:/usr/local/mycat/lib/univocity-parsers-1.5.4.jar:/usr/local/mycat/lib/wrapper. jar:/usr/local/mycat/lib/xml-apis-1.0.b2.jar:/usr/local/mycat/lib/zookeeper-3.4.6.jar "-server-Xms2G-Xmx2G-XX: MaxPermSize = 64 M-XX: + AggressiveOpts-XX: MaxDirectMemorySize = 2G org. opencloudb. mycatStartup> "/usr/local/mycat/logs/console. log "2> & 1 &

MySQL read/write splitting using MyCAT

MySQL read/write splitting using MyCAT

Verify MyCAT ER sharding

Build a MyCAT high-availability server Load balancer cluster using LVS + Keepalived

This article permanently updates the link address:

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.