Remember once Java application CPU utilization too high debugging experience

Source: Internet
Author: User
Tags high cpu usage
1, phenomenon

Write a storm application that synchronizes the table to hbase primarily via MySQL's binlog. After running for a period of time found that the CPU usage often soared to more than 200%, and then a variety of message accumulation alarm and so on, there are various problems

2, research process

CPU usage is high, so first find the process, through the top command, monitor the utilization of the process, and then through H, see the CPU utilization of each thread, note the high CPU utilization of the thread ID, and then through the Jstack PID, get the individual line stacks, After listening to the thread ID of top gets converted to 16, the thread stack that found the problem is as follows:

The main problem was found on the HashMap put. It is strange that only one spout should be single-threaded, but later found that the client side is multithreaded from NSQ to fetch data. HashMap is not thread-safe, so in multi-threading, a dead loop can cause high CPU usage. Specific reasons can be see: http://coolshell.cn/articles/9606.html

3, processing method:

Find the problem, through code discovery conversion JSON to map after not specified Concurrenthashmap, and then put the data caused, directly by replacing into Concurrenthashmap just fine.

4, summary

HashMap is not thread-safe and must not be used in multithreaded processes. In addition, encountered in Java application CPU usage is high, should be able to use the above solutions to locate.

Remember once Java application CPU utilization too high debugging experience

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.