A summary of Java problem locating methods

Source: Internet
Author: User

Background
"Offline no Problem", "code can not have a problem is the system reason", "to be able to online remote debugging?"
The online problem differs from the bug during development, and is related to the runtime environment, stress, concurrency, and specific business. For online issues using tools available on the online environment, gathering the necessary information is important for locating problems.
For the bug that causes the problem, the resource bottleneck is difficult to obtain the data intuitively, need to speculate the problem source according to the Resource usage data, log and so on information. And the location of the problematic problem usually requires a different approach to the traced.
This wiki I have used the tools I have done to organize and share some cases.

1. Frequently Asked Questions
1.1 Availability
Here are a few common scenarios that lead to service availability:
A) 502 bad Gateway
The worst thing about application systems, especially HTTP-based applications, is "502 Bad Gateway", which indicates that the backend service is completely unavailable, possibly because
Less than 1 of resources: garbage collection causes severe application pauses when the CMS is applying memory leaks or low memory conditions.
Less than 2 resources: the number of server threads is low, and common Web servers such as Tomcat jetty are configured with the maximum worker thread
Less than 3 resources: Database resources are not available, databases typically use connection pooling configuration, maxconnection configuration is low, and too many slow queries block Web server worker threads
Resources are not 4:io resource bottleneck, online environment Io is shared, especially for mixed environment (CRM is OK without this situation, but there are many agents), our common log4j log tool for each log file is also an exclusive resource, the thread first to obtain a lock to log data to the logging.
... ...
Various Oom
b) Socket exception
Common connection reset by Peer,broken pipe,eofexception
Network problems: In the case of cross-carrier, computer room access may encounter
Program Bug:socket Abnormal shutdown
1.2 Average response time
System problems when the most intuitive appearance, this parameter in the case of deterioration of the infection of other services resulting in the entire system is not available before, can be early warning, possible reasons:
Resource Competition 1:cpu
Resource Competition 2:io
Resource Competition 3:network IO
Resource Competition 4: Database
Resource competition 5:SOLR, Medis
Downstream interface: Exception causes response delay

1.3 Machine Alarms
This type of error does not directly result in service unavailability compared to application service unavailability, and if there is no mix, the machine deploys multiple services that may interfere with each other:
Cpu
Disk
Fd
IO (Network disk)
1.4 Summary
Write for a long, many cases are repeated mentioned, usually the cause of online problems is not only the system resources, applications, master monitoring to view these resources, data tools to more easily locate the problem on the line.
2 Common Tools
2.1 Linux Tools
A) Sysstat:
Iostat: View read/write pressure

    [[email protected] logs]$ iostat    Linux  2.6.32-20131120.mt  (cos-mop01.lf.sankuai.com)      2015 October 21       _x86_64_     (4 CPU)     avg-cpu:  %user    %nice %system %iowait  %steal   %idle                1.88    0.00     0.87    0.12    0.05   97.07     Device:            tps    Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn     vda                1.88        57.90        12.11 2451731906   512911328    vdb                0.01         0.40          1.41   17023940   59522616    vdc                1.14         28.88        36.63 1223046988  1551394969

SAR: View CPU network IO io, turn on parameters to view historical data

/etc/sysconfig/sysstat History=7/etc/cron.d/sysstat */10 * * * * ROOT/USR/LIB/SA/SA1 1 1 sar-u/-r/-b/ -b/-q/-p/-n-f/var/log/sa/sa09

b) Top
Focus on load, CPU, mem, swap
Resource information can be viewed by thread (version greater than 3.2.7)

Top - 19:33:00 up 490 days,  4:33,  2 users,  load  average: 0.13, 0.39, 0.42tasks: 157 total,   1 running,  156 SLEEPING,   0 STOPPED,   0 ZOMBIECPU (s):   4.9 %us,  2.7%sy,  0.0%ni, 92.2%id,  0.0%wa,  0.0%hi,  0.0% si,  0.3%stmem:   5991140k total,  5788884k used,    202256k free,     4040k buffersswap:  2096440k total,    447332k used,  1649108k free,   232884k cached   PID USER      PR  NI  VIRT  RES   SHR S %CPU %MEM    TIME+  SWAP CODE DATA  Command18720 sankuai   20   0 8955m 4.3g 6744 s 22.6 74.5  174:30.73    0    4 8.6g java27794 sankuai    20   0 5715m 489m 2116 S 11.6  8.4    3922:43 121m    4 3.9g java13233 root       20   0  420m 205m 2528 S  0.0  3.5    1885:15  91m    4 304m puppetd21526 sankuai    20   0 2513m  69m 4484 s  0.0  1.2   45:56.28  37m    4 2.4g java


c) Vmstat

[Email protected] logs]$ vmstatprocs-----------memory-------------Swap-------io------System-------CPU-----R B SW     PD free buff cache si so bi bo in CS us sy ID WA St 0 0 447332 200456 4160 234512 0 0 11 6 0 0 2 1 97 0 0


D) tcpdump

Locate the network problem artifact, you can see the details of the TCPIP message, need to be familiar with the TCPIP protocol, can be used in conjunction with Wireshark.
Common scenario Analysis network delay, network packet loss, complex environment network problem analysis.

#!/bin/bashtcpdump-i eth0-s 0-l-w-dst Port 3306 | Strings |    Perl-e ' while (<>) {chomp; next if/^[^]+[]*$/; if (/^ (select| update| delete| Insert| Set| Commit| rollback| create| drop| alter|        Call) {if (defined $q) {print "$q \ n";}    $q =$_;    } else {$_ =~ s/^[\t]+//; $q. = "$_"; }}‘

3.2 Java Tools
A) Jstat

[[email protected] logs]$ jstat -gc 18704 s0c    s1c     S0U    S1U      EC        EU        OC          OU       MC     MU     CCSC   CCSU   YGC     YGCT     fgc    fgct     gct3584.0 3584.0  0.0     0.0   24064.0  13779.7   62976.0       0.0     4480.0 677.9  384.0    66.6       0    0.000   0       0.000    0.000 


b) Jmap

Jmap-dump:format=b,file=heap.bin $pid


c) Jstack or kill-3
View deadlocks, thread waits.
Thread State:
Running
Timed_waiting (on object monitor)
Timed_waiting (sleeping)
Timed_waiting (parking)
Wainting (on object monitor)

d) Jhat Jconsole
Jhat It's hard to use Jconsole to get information from JMX to performance impact
E) GC Log
-xx:+useparallelold
-xx:+concurrentmultisweep
3.3 Third-party tools
A) Mat
Object Details
650) this.width=650; "title=" QQ20170319-0@2x.png "alt=" wkiom1joeiihjo5vabuyouiacfy210.png-wh_50 "src=" https:// S4.51cto.com/wyfs02/m01/8e/e3/wkiom1joeiihjo5vabuyouiacfy210.png-wh_500x0-wm_3-wmp_4-s_3139704531.png "/>

Inboud/outbound
650) this.width=650; "title=" QQ20170319-1@2x.png "alt=" wkiom1joeskafp7maawsee0mvic859.png-wh_50 "src=" https:// S2.51cto.com/wyfs02/m02/8e/e3/wkiom1joeskafp7maawsee0mvic859.png-wh_500x0-wm_3-wmp_4-s_3853883834.png "/>

Thread overview
650) this.width=650; "title=" QQ20170319-3@2x.png "alt=" wkiom1joextcounqaa7wglxagsk681.png-wh_50 "src=" https:// S2.51cto.com/wyfs02/m00/8e/e3/wkiom1joextcounqaa7wglxagsk681.png-wh_500x0-wm_3-wmp_4-s_2394103711.png "/>

Configuration Items
650) this.width=650; "title=" QQ20170319-2@2x.png "alt=" wkiol1joeuojmypzaakatt0dfzu577.png-wh_50 "src=" https:// S4.51cto.com/wyfs02/m02/8e/e1/wkiol1joeuojmypzaakatt0dfzu577.png-wh_500x0-wm_3-wmp_4-s_678646480.png "/>

./memoryanalyzer-keep_unreachable_objects Heap_file
4. Case studies
4.1 CPU High

Symptom: CPU Alarm
Positioning issues:
View threads with high CPU usage

[Email protected]:~$ ps h -eo user,pid,ppid,tid,time,%cpu|sort -rnk6 |head  -10sankuai  13808 13807 13808 00:00:00  8.4sankuai  29153      1 29211 00:21:13  0.9sankuai  29153      1 29213 00:20:01  0.8sankuai  29153      1 29205 00:17:35  0.7sankuai  29153     1  29210 00:11:50  0.5sankuai  29153     1  1323  00:08:37  0.5sankuai  29153     1 29207 00:10:02   0.4sankuai  29153     1 29206 00:07:10   0.3sankuai  29153     1 29208 00:06:44  0.2

Thread Dump

Jstack $pid > A.txt printf%x $tid $xTID

Find code executed by thread

"Main-sendthread (cos-zk13.lf.sankuai.com:9331)" #25 daemon prio=5 os_prio=0 tid=0x00007f78fc350000 nid= $TIDx runnable [0x00007f79c4d09000]java.lang.thread.state:runnable at Org.apache.zookeeper.clientcnxn$sendthread.run ( clientcnxn.java:1035) at Java.util.concurrent.FutureTask.run (futuretask.java:266) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1142) at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:617) at Java.lang.Thread.run ( thread.java:745)

4.2 Io High

Symptom: Disk IO alarm
Environment: Need to install Sysstat tool
Positioning issues:
A) View threads with high CPU usage

pidstat-d-t-p $pid


b) Other same 4.1

4.3 Resources
A) database

"Db-processor-13"  daemon prio=5 tid=0x003edf98 nid=0xca waiting for monitor  entry [0x000000000825f000]java.lang.Thread.State: BLOCKED  (On object monitor)                 at  Connectionpool.getconnection (connectionpool.java:102)                  - waiting to lock <0xe0375410>  (A  beans. ConnectionPool)                  at service.getcount (servicecnt.java:111)                  at service.insert (servicecnt.java:43) "DB-Processor-14"   daemon prio=5 tid=0x003edf98 nid=0xca waiting for monitor entry [ 0x000000000825f020]java.lang.thRead. state: blocked  (On object monitor)                  at connectionpool.getconnection (ConnectionPool.java:102)                  - waiting  to lock <0xe0375410>  (A beans. ConnectionPool)                  at service.getcount (servicecnt.java:111)                  at service.insertcount (servicecnt.java:43)

b) Log

"RMI TCP Connection (267865) -172.16.5.25" daemon prio=10tid=0x00007fd508371000 nid=0x55ae waiting for Monitor entry[ 0X00007FD4F8684000] Java.lang.Thread.State:BLOCKED (on object monitor) at Org.apache.log4j.Category.callAppenders ( category.java:201)-Waiting to lock <0x00000000acf4d0c0> (a Org.apache.log4j.Logger) at Org.apache.log4j.Category.forcedLog (category.java:388) at Org.apache.log4j.Category.log (category.java:853) at Org.apache.commons.logging.impl.Log4JLogger.warn (log4jlogger.java:234) at Com.xxx.core.common.lang.cache.remote.MemcachedClient.get (memcachedclient.java:110)


C) Web server

has two very important system parameters:

Maxthread: Number of worker threads

backlog:tcp Number of connection caches, Jetty ( serverconnector.acceptqueuesize) Tomcat (Connector.acceptcount), with high concurrency set too small will have 502

 
4.4 gc

A) CMS fail
    promotion failed

    172966 2015-09-18t03:47:33.108+0800: 627188.183: [gc 627188.183:  [ParNew  (promotion failed)      172967 desired survivor  size 17432576 bytes, new threshold 1  (max 6)       172968 - age   1:   34865032 bytes,    34865032 total     172969 : 306688k->306688k (306688K),  161.1284530 secs]627349.311: [cms cms: abort preclean due to time  2015-09-18t03:50:14.743+0800: 627349.818:    [cms-concurrent-abortable-preclean :  1.597/162.729 secs] [times: user=174.58 sys=84.57, real=162.71 secs]      172970   (concurrent mode failure):  1550703k->592286k (1756416K),  2.9879760 secs]    1755158k->592286k (2063104K),  [cms perm : 67701k->67695k (112900K) ], 164.1167250 secs] [times: user=175.61 sys=84.57, real=164.09 secs]

Concurrent fail

[cms2015-09-18t07:07:27.132+0800:639182.207: [cms-concurrent-sweep:1.704/13.116 secs] [times:user=17.16 sys=5.20, real=13.12 secs] 443222 (concurrent mode failure): 1546078k->682301k (1756416K), 4.0745320 secs] 1630977k->682301k (2063104K), [CMS perm:67700k->67693k (112900K)], 15.4860730 secs] [times:user=19.40 sys=5.20, real=15.48 secs]

b) Continuous full GC

There is a memory leak in the application, garbage collection takes up a lot of CPU time in the system, and in extreme cases it can happen more than 90% times in GC.
When the system uses HTTP to access the check alive or uses zookeeper to survive the heartbeat, the usability anomaly or the ZK master is removed.


5. Note
Reserved on site: Threaddump top Heapdump
Note Logging: File database

This article from "Ying: good memory is inferior to bad writing" blog, please be sure to keep this source http://yingtju.blog.51cto.com/3760152/1908197

A summary of Java problem locating methods

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.