Pits Netty Io.netty.util.internal.OutOfDirectMemoryError

Source: Internet
Author: User

We have an interface with external interaction is adopted Netty HTTP, specific version netty-4.1.18, why use this version, I do not know, historical reasons.

Since Netty are asynchronous requests, there is always a unique business identity with external interactions that needs to be saved so that data can be blended before and after.

It is explained here that the bytebuf in the Netty need to release releases on their own when reading the channelread without writing the write operation. This is not related to this error, continue to say the key.

Check the log, first found the Outofdirectmemoryerror error, this error is also intermittent appearance, is obviously not enough memory, whether it is heap or direct.

Directly dump a copy of the heap memory log, the specific command: Jmap-dump:format=b,file=tomcat.dump PID. Our service is put on Tomcat, JPS, that Bootstrap is.

After dump, find the tool to see, recommend the use of Java JVISUALVM, in the Java directory of the bin, Java comes with the command is very useful, such as the above mentioned jps,jps-v than Ps-ef |grep XXX more convenient.

After loading the dump file:

Probably a glance, some instances of the class is also more, the whole of the Concurrenthashmap, Cliff has a problem, so make memory enough to blame, and then see the following netty about the class instance,

See Code use Attributekey Place, and see the source implementation, probably some of the things, should be the object created too much, resulting in memory overflow.

Each instance hangs this one concurrenthashmap, does not know whether our usage has the question, first regardless, first solves the problem,

Discovery code Each request creates a connection channel, each time the global save a Attributekey, in order to request an asynchronous response, blending raw data, so, millions of requests a day a little Chunkun autumn,

Borrow Attributekey's idea, instead of the global save a concurrenthashmap, then the key value pair to save the unique business identity, and after the asynchronous processing remove obsolete data.

Attributekey I turned over the source, I really did not see where to release the place, there is a set (null) of course the code is not used after the empty operation, but the Attributekey internal Haspmap is not automatically released.

After modification, redeploy. Observed for several days, dump a new memory log, and did not find too many object instances. Keep watching for a while.

In fact, the problem of memory overflow is not so difficult, memory is not enough to naturally fullgc or memory overflow, some memory leaks will eventually cause FULLGC or memory overflow, find too many garbage objects,

The release of the release, the singleton use of a single case, can be reused as far as possible reuse, should be no problem, look at the dump file basically found the root cause of the problem.

Pits Netty Io.netty.util.internal.OutOfDirectMemoryError

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.